本文共 5152 字,大约阅读时间需要 17 分钟。
往往在我们删除一个容器后又用相同镜像进行部署时,我们做的更改的那个镜像里面的数据会丢失,假如我们想要重新使用我们改变后的镜像作为一个源,怎么做?请看解决方案
我们可以通过docker commit来完成,并且定义一个新的镜像
$ docker run -t -i ubuntu:14.04 /bin/bash
[root@c720120 ~]# docker run -t -i ubuntu:14.04 /bin/bash
、
root@8c892f17fc59:/# apt-get update Get:1 http://security.ubuntu.com trusty-security InRelease [65.9 kB]Get:2 http://security.ubuntu.com trusty-security/universe Sources [88.8 kB]Get:3 http://security.ubuntu.com trusty-security/main amd64 Packages [919 kB]Ign http://archive.ubuntu.com trusty InRelease Get:4 http://archive.ubuntu.com trusty-updates InRelease [65.9 kB] Get:5 http://security.ubuntu.com trusty-security/restricted amd64 Packages [18.1 kB]Get:6 http://archive.ubuntu.com trusty-backports InRelease [65.9 kB] Get:7 http://security.ubuntu.com trusty-security/universe amd64 Packages [290 kB]Get:8 http://archive.ubuntu.com trusty Release.gpg [933 B] Get:9 http://archive.ubuntu.com trusty-updates/universe Sources [253 kB] Get:10 http://security.ubuntu.com trusty-security/multiverse amd64 Packages [4725 B]Get:11 http://archive.ubuntu.com trusty-updates/main amd64 Packages [1344 kB] Get:12 http://archive.ubuntu.com trusty-updates/restricted amd64 Packages [21.4 kB]Get:13 http://archive.ubuntu.com trusty-updates/universe amd64 Packages [586 kB]Get:14 http://archive.ubuntu.com trusty-updates/multiverse amd64 Packages [16.0 kB]Get:15 http://archive.ubuntu.com trusty-backports/main amd64 Packages [14.7 kB]Get:16 http://archive.ubuntu.com trusty-backports/restricted amd64 Packages [40 B]Get:17 http://archive.ubuntu.com trusty-backports/universe amd64 Packages [52.5 kB]Get:18 http://archive.ubuntu.com trusty-backports/multiverse amd64 Packages [1392 B]Get:19 http://archive.ubuntu.com trusty Release [58.5 kB] Get:20 http://archive.ubuntu.com trusty/universe Sources [7926 kB] Get:21 http://archive.ubuntu.com trusty/main amd64 Packages [1743 kB] Get:22 http://archive.ubuntu.com trusty/restricted amd64 Packages [16.0 kB] Get:23 http://archive.ubuntu.com trusty/universe amd64 Packages [7589 kB] Get:24 http://archive.ubuntu.com trusty/multiverse amd64 Packages [169 kB] Fetched 21.3 MB in 37s (572 kB/s) Reading package lists... Done
[root@c720120 ~]# docker commit 8c89 ubuntu:updatesha256:2292f220bc30f7aa1bb08a795f8ecd5ac58f58a94705c899b1d2d96fa353a584
我们也可以通过diff选项来看在原镜像和现在的镜像之间有哪些改变。
[root@c720120 ~]# docker diff 8c89C /rootA /root/.bash_historyC /tmpC /varC /var/cacheC /var/cache/aptD /var/cache/apt/pkgcache.binD /var/cache/apt/srcpkgcache.binC /var/libC /var/lib/apt/listsA /var/lib/apt/lists/archive.ubuntu.com_ubuntu_dists_trusty-backports_InReleaseA /var/lib/apt/lists/archive.ubuntu.com_ubuntu_dists_trusty-backports_main_binary-amd64_Packages.gzA /var/lib/apt/lists/archive.ubuntu.com_ubuntu_dists_trusty-backports_multiverse_binary-amd64_Packages.gzA /var/lib/apt/lists/archive.ubuntu.com_ubuntu_dists_trusty-backports_restricted_binary-amd64_Packages.gzA /var/lib/apt/lists/archive.ubuntu.com_ubuntu_dists_trusty-backports_universe_binary-amd64_Packages.gzC /var/lib/apt/lists/archive.ubuntu.com_ubuntu_dists_trusty-updates_InReleaseA /var/lib/apt/lists/archive.ubuntu.com_ubuntu_dists_trusty-updates_main_binary-amd64_Packages.gzA /var/lib/apt/lists/archive.ubuntu.com_ubuntu_dists_trusty-updates_multiverse_binary-amd64_Packages.gzA /var/lib/apt/lists/archive.ubuntu.com_ubuntu_dists_trusty-updates_restricted_binary-amd64_Packages.gzA /var/lib/apt/lists/archive.ubuntu.com_ubuntu_dists_trusty-updates_universe_binary-amd64_Packages.gzA /var/lib/apt/lists/archive.ubuntu.com_ubuntu_dists_trusty-updates_universe_source_Sources.gzC /var/lib/apt/lists/archive.ubuntu.com_ubuntu_dists_trusty_ReleaseC /var/lib/apt/lists/archive.ubuntu.com_ubuntu_dists_trusty_Release.gpgA /var/lib/apt/lists/archive.ubuntu.com_ubuntu_dists_trusty_main_binary-amd64_Packages.gzA /var/lib/apt/lists/archive.ubuntu.com_ubuntu_dists_trusty_multiverse_binary-amd64_Packages.gzA /var/lib/apt/lists/archive.ubuntu.com_ubuntu_dists_trusty_restricted_binary-amd64_Packages.gzA /var/lib/apt/lists/archive.ubuntu.com_ubuntu_dists_trusty_universe_binary-amd64_Packages.gzA /var/lib/apt/lists/archive.ubuntu.com_ubuntu_dists_trusty_universe_source_Sources.gzC /var/lib/apt/lists/lockC /var/lib/apt/lists/partialC /var/lib/apt/lists/security.ubuntu.com_ubuntu_dists_trusty-security_InReleaseA /var/lib/apt/lists/security.ubuntu.com_ubuntu_dists_trusty-security_main_binary-amd64_Packages.gzA /var/lib/apt/lists/security.ubuntu.com_ubuntu_dists_trusty-security_multiverse_binary-amd64_Packages.gzA /var/lib/apt/lists/security.ubuntu.com_ubuntu_dists_trusty-security_restricted_binary-amd64_Packages.gzA /var/lib/apt/lists/security.ubuntu.com_ubuntu_dists_trusty-security_universe_binary-amd64_Packages.gzA /var/lib/apt/lists/security.ubuntu.com_ubuntu_dists_trusty-security_universe_source_Sources.gzC /var/lib/dpkgC /var/lib/dpkg/lock
其中A代表新添加的
其中C代表改变的其中D代表删除的技术讨论群:190029784
转载于:https://blog.51cto.com/aishangwei/2120802