Docker镜像的打包部署

启动个docker

C:\Users\docker>docker images
REPOSITORY           TAG                 IMAGE ID            CREATED             SIZE
centos               latest              e934aafc2206        2 months ago        199MB

C:\Users\docker>docker run -it centos /bin/bash
[root@ebaef8570358 /]# ls
anaconda-post.log  bin  dev  etc  home  lib  lib64  media  mnt  opt  proc  root  run  sbin  srv  sys  tmp  usr  var

在这个docker上做些修改

[root@ebaef8570358 /]# echo 'hello word' >/tmp/hello_word.txt
[root@ebaef8570358 /]# ls /tmp
hello_word.txt  ks-script-hE5IPf  yum.log

查看修改的内容

[root@9e567dad37a5 /]# exit
exit

C:\Users\docker>docker diff 9e56
C /root
A /root/.bash_history
C /tmp
A /tmp/hello_word.txt

C: Change
A: Add
D: Delete

提交修改到镜像

C:\Users\docker>docker commit 9e567 centos:update
sha256:43442c42ff38a02f2da0cc1dc5a6d6dafdd5e3e38c275ad26e341ef646779c22

看一下镜像有没有保存好

C:\Users\docker>docker images
REPOSITORY           TAG                 IMAGE ID            CREATED             SIZE
centos               update              43442c42ff38        32 seconds ago      199MB
centos               latest              e934aafc2206        2 months ago        199MB

导出和导入

C:\Users\docker>docker export 9e567 >centos_v1.tar

C:\Users\docker>dir centos_v1.tar
centos_v1.tar

C:\Users\docker>docker import - centos_v1 <centos_v1.tar
sha256:b5ab33184f364c79e78a9e8ca699b6171ce958cdff6b43c904017fac9f2ba6ca

C:\Users\gchen1>docker images
REPOSITORY           TAG                 IMAGE ID            CREATED              SIZE
centos_v1            latest              b5ab33184f36        About a minute ago   199MB
centos               update              43442c42ff38        7 minutes ago        199MB
centos               latest              e934aafc2206        2 months ago         199MB

镜像的备份和恢复

C:\Users\docker>docker save -o centos_backup.tar centos:update

C:\Users\docker>dir centos_bakup.tar
centos_backup.tar

C:\Users\docker>docker load <centos_backup.tar 

C:\Users\docker>docker rmi centos:update
Untagged: centos:update
Deleted: sha256:43442c42ff38a02f2da0cc1dc5a6d6dafdd5e3e38c275ad26e341ef646779c22
Deleted: sha256:6fe11269af1f253b2d234c0c81833744818c7ac5eb6e4ec343ab9628103333f4

C:\Users\docker>docker load <centos_backup.tar
7948c8051341: Loading layer [==================================================>]  4.096kB/4.096kB
Loaded image: centos:update

C:\Users\docker>docker images
REPOSITORY           TAG                 IMAGE ID            CREATED             SIZE
centos_v1            latest              b5ab33184f36        9 minutes ago       199MB
centos               update              43442c42ff38        16 minutes ago      199MB
centos               latest              e934aafc2206        2 months ago        199MB
Logo

权威|前沿|技术|干货|国内首个API全生命周期开发者社区

更多推荐