8创建镜像
Posted jie-fang
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了8创建镜像相关的知识,希望对你有一定的参考价值。
8.1 通过Container创建镜像
??命令:
docker container commit <==> docker commit
[[email protected] ~]# docker run -it centos
[[email protected] /]# yum install -y vim
[[email protected] /]# exit
exit
[[email protected] ~]# docker container -aq #获取容器的ID
41fec031cde0
[[email protected] ~]# docker commit 41fec031cde0 staryjie/centos-vim
sha256:7f25650f744f3a9e72e6d7fce30841f32fb15103b54e97863f289e7c75cd1f29
[[email protected] ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
staryjie/centos-vim latest 7f25650f744f 34 seconds ago 324MB
staryjie/hello-docker latest 09be7d865fab About an hour ago 865kB
ubuntu 14.04 8cef1fa16c77 4 weeks ago 223MB
ubuntu latest 452a96d81c30 4 weeks ago 79.6MB
hello-world latest e38bc07ac18e 7 weeks ago 1.85kB
centos latest e934aafc2206 7 weeks ago 199MB
8.2 通过Dockerfile创建镜像
??命令:
docker image build <==> docker build
??编写Dockerfile:
FROM centos
RUN yum install -y vim
??构建镜像:
[[email protected] ~]# docker build -t staryjie/centos-vim-new .
Sending build context to Docker daemon 2.048kB
Step 1/2 : FROM centos
---> e934aafc2206
Step 2/2 : RUN yum install -y vim
---> Running in c96490b78363 #构建是临时创建的container的ID
Removing intermediate container c96490b78363
---> b717d7ce6840
Successfully built b717d7ce6840
Successfully tagged staryjie/centos-vim-new:latest
[[email protected] ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
staryjie/centos-vim-new latest b717d7ce6840 About a minute ago 324MB
staryjie/centos-vim latest 7f25650f744f 10 minutes ago 324MB
staryjie/hello-docker latest 09be7d865fab About an hour ago 865kB
ubuntu 14.04 8cef1fa16c77 4 weeks ago 223MB
ubuntu latest 452a96d81c30 4 weeks ago 79.6MB
hello-world latest e38bc07ac18e 7 weeks ago 1.85kB
centos latest e934aafc2206 7 weeks ago 199MB
[[email protected] ~]#
以上是关于8创建镜像的主要内容,如果未能解决你的问题,请参考以下文章
8.Docker技术入门与实战 --- 使用Dockerfile创建镜像