1. 程式人生 > >docker通過運行容器制作共享tar鏡像包

docker通過運行容器制作共享tar鏡像包

docker docker制作tar docker基於運行的容器制作鏡像

  • 鏡像構建:
    docker commit 【option】
    -a 指明作者
    -p 暫停容器再建立鏡像

    [root@vichost ~]# docker commit -p -a "vicliaoxz <[email protected]>" centos2
    sha256:ead743182b50ba021d5eee144aad229cbcf093f6796363b11e366f6117a62fab
    [root@vichost ~]# docker images
    REPOSITORY            TAG                 IMAGE ID            CREATED              SIZE
    <none>                <none>              ead743182b50        About a minute ago   302 MB
    [root@vichost ~]# docker run -it --name c-net-tools ead743182b50
    [root@ff3b674ffa51 /]# ifconfig
    eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 172.17.0.4  netmask 255.255.0.0  broadcast 0.0.0.0
        inet6 fe80::42:acff:fe11:4  prefixlen 64  scopeid 0x20<link>
  • 給鏡像添加標簽

    docker tag SOURCE_IMAGE[:TAG] TARGET_IMAGE[:TAG]
    [root@vichost ~]# docker tag ead743182b50(ID) vicdockerhub(用戶名)/centos(基礎鏡像):net-tools(標簽)
    [root@vichost ~]# docker images
    REPOSITORY            TAG                 IMAGE ID            CREATED             SIZE
    vicdockerhub/centos   net-tools           ead743182b50        21 minutes ago      302 MB
  • 推送鏡像
    3.1.推送到docker-hub(需要註冊一個dockerhub賬號)
    [root@vichost ~]# docker login -u vicdockerhub 
    Password: 
    Login Succeeded
    [root@vichost ~]# docker push vicdockerhub/centos:net-tools 
    The push refers to a repository [docker.io/vicdockerhub/centos]
  • 3.2.上傳到私有倉庫:
    docker tag vicdockerhub/centos:net-tools myregistry.liaoxz.xin:5000/vicdockerhub/centos:net-tools

    1. 將鏡像保存為tar包
      docker ecport 導出為一個容器
      
      Usage:  docker save [OPTIONS] IMAGE [IMAGE...]
      Options:
      -o, --output string   Write to a file, instead of STDOUT

    [root@vichost ~]# docker save vicdockerhub/centos:net-tools -o centos-net-tools.tar
    [root@vichost ~]# ls
    centos-net-tools.tar

    
    
    5. 外部tar包導入鏡像
    docker load
    docker load -i 指定鏡像tar包
    
    [root@vichost ~]# docker load -i centos-net-tools.tar 
    Loaded image: vicdockerhub/centos:net-tools
    [root@vichost ~]# docker images
    REPOSITORY                                       TAG                 IMAGE ID            CREATED             SIZE
    myregistry.liaoxz.xin:5000/vicdockerhub/centos   net-tools           ead743182b50        51 minutes ago      302 MB
    vicdockerhub/centos                              net-tools           ead743182b50        51 minutes ago      302 MB

    docker通過運行容器制作共享tar鏡像包