标签:Dockerfile编写
Dockerfile两种方式对比:#### (1) 编写Dockerfile文件
vim Dockerfile
FROM ubuntu:14.04
ENTRYPOINT ["/bin/echo"]
[root@c720120 docker]# docker build .
Sending build context to Docker daemon 2.048kB
Step 1/2 : FROM ubuntu:14.04
---> 8cef1fa16c77
Step 2/2 : ENTRYPOINT ["/bin/echo"]
---> Running in aaad472bad79
Removing intermediate container aaad472bad79
---> 8142eaef4d70
Successfully built 8142eaef4d70
[root@c720120 docker]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
<none> <none> 8142eaef4d70 About a minute ago 223MB
[root@c720120 docker]# docker run 814 Hi Docker !
Hi Docker !
注意:当容器执行完命令后,就会进入停止状态,这时如果我们想要运行该容器的话,执行以下命令:[root@c720120 docker]# docker run 814
[root@c720120 docker]# cat Dockerfile
FROM ubuntu:14.04
ENTRYPOINT ["/bin/echo“ , "Hi Docker !"]
[root@c720120 docker]# docker build .
Sending build context to Docker daemon 2.048kB
Step 1/2 : FROM ubuntu:14.04
---> 8cef1fa16c77
Step 2/2 : ENTRYPOINT ["/bin/echo" , "Hi Docker !"]
---> Running in 7d9577b1d2e1
Removing intermediate container 7d9577b1d2e1
---> 3b1ac59ac602
[root@c720120 docker]# docker run 3b1
Hi Docker !
从以上查看镜像时看到,镜像是没有标签的,如果要指定标签,按以下命令行的格式来做。
[root@c720120 docker]# docker build -t cookbook:hello .
Sending build context to Docker daemon 2.048kB
Step 1/2 : FROM ubuntu:14.04
---> 8cef1fa16c77
Step 2/2 : ENTRYPOINT ["/bin/echo" , "Hi Docker !"]
---> Using cache
---> 3b1ac59ac602
Successfully built 3b1ac59ac602
Successfully tagged cookbook:hello
再次查看镜像:
Dockerfile学习参考地址:
https://docs.docker.com/reference/builder/
https://docs.docker.com/articles/dockerfile_best-practices/
标签:Dockerfile编写
原文地址:http://blog.51cto.com/aishangwei/2120807