通过修改然后commit的方式创建自己的镜像
通过修改然后commit的方式创建自己的镜像
创建自己的镜像:通过现有的镜像来创建自己的镜像。
1、首先拉取一个镜像到本地
$ sudo docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
ubuntu 12.04 5b117edd0b76 11 months ago 104 MB
2、进入容器
$ sudo docker run -it ubuntu:12.04 bash
$ root@7a61867cf4c5:/#
3、修改容器,这里我们安装zip包
# apt-get install zip
Reading package lists… Done
Building dependency tree
Reading state information… Done
E: Unable to locate package zip
需要更新,我们更新
root@7a61867cf4c5:/# apt-get update
结束后
root@7a61867cf4c5:/# apt-get install zip
修改后退出
root@7a61867cf4c5:/# exit
exit
4、保存容器到镜像
$ sudo docker commit -m ‘test’ -a ‘zhouhai’ 7a61867cf4c5 ubuntu:latest
sha256:763d1f40ca6b4a801a78b39ddeb526be44330bb65f4ef94dc9267e4f0985627c
查看镜像
$ sudo docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
ubuntu latest 763d1f40ca6b 13 seconds ago 133 MB
ubuntu 12.04 5b117edd0b76 11 months ago 104 MB
5、导出新产生的镜像
$ sudo docker save -o /home/zh/ubuntu_zip.tar ubuntu:latest
6、删除新产生的镜像
$ sudo docker rmi -f ubuntu:latest
Untagged: ubuntu:latest
Deleted: sha256:763d1f40ca6b4a801a78b39ddeb526be44330bb65f4ef94dc9267e4f0985627c
Deleted: sha256:e6e720db3d4ce9b5b07f4e77e6c0608add2d83b218f2b3107800682e29be246b
查看一下
$ sudo docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
ubuntu 12.04 5b117edd0b76 11 months ago 104 MB
7、导入刚才保存的镜像
$ sudo docker load –input /home/zh/ubuntu_zip.tar
83c5e276e2c0: Loading layer [==================================================>] 29.82 MB/29.82 MB
Loaded image: ubuntu:latest
查看一下
$ sudo docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
ubuntu latest 763d1f40ca6b 16 minutes ago 133 MB
ubuntu 12.04 5b117edd0b76 11 months ago 104 MB
进入容器
$ sudo docker run -it ubuntu:latest bash
root@9d1ab685dd74:/# zip
Copyright (c) 1990-2008 Info-ZIP – Type ‘zip “-L”‘ for software license.
Zip 3.0 (July 5th 2008). Usage:
zip [-options] [-b path] [-t mmddyyyy] [-n suffixes] [zipfile list] [-xi list]
The default action is to add or replace zipfile entries from list, which
can include the special name – to compress standard input.
If zipfile and list are omitted, zip compresses stdin to stdout.
-f freshen: only changed files -u update: only changed or new files
-d delete entries in zipfile -m move into zipfile (delete OS files)
-r recurse into directories -j junk (don’t record) directory names
-0 store only -l convert LF to CR LF (-ll CR LF to LF)
-1 compress faster -9 compress better
-q quiet operation -v verbose operation/print version info
-c add one-line comments -z add zipfile comment
-@ read names from stdin -o make zipfile as old as latest entry
-x exclude the following names -i include only the following names
-F fix zipfile (-FF try harder) -D do not add directory entries
-A adjust self-extracting exe -J junk zipfile prefix (unzipsfx)
-T test zipfile integrity -X eXclude eXtra file attributes
-y store symbolic links as the link instead of the referenced file
-e encrypt -n don’t compress these suffixes
-h2 show more help
大功告成!