dockerfile 基础

Author: yifei / Created: June 27, 2017, 11:54 a.m. / Modified: June 27, 2017, 12:33 p.m. / Edit

Dockerfile 列出了构建一个docker image 的可复现步骤。比起一步一步通过 docker commit 来制作一个镜像,dockerfile更适用于CI自动测试等系统。

Dockerfile 命令



ADD 会自动解压压缩包,在不需要特殊操作的时候,最好使用COPY。


entrypoint 指定了 Docker 镜像要运行的二进制文件(当然也包括参数),而 cmd 则指定了运行这个二进制文件的参数。不过因为默认 entrypoint 是 bash -c,所以实际上 CMD 指定的也是要运行的命令。

另外,docker run 时候包含命令行参数,会执行命令行参数,而不是 CMD 的内容。

个人倾向于只使用 CMD,而不使用 ENTRYPOINT


使用Dockerfile 还是 commit 来构建镜像

using dockerfile is the best solution if possible, however it's not that easy.

I've been wondering the same thing, and my impression (which could be totally wrong) it that it's really the same case as with VMs --> you don't want to not know how to recreate the vm image. In my case I have regular .sh scripts to install, and am wondering why I can't just maintain these, run docker and effectively call these, and create the golden version image that way. My scripts work to get it installed on a local PC, and the reason I want to use docker is to deal with conflicts of multiple instances of programs/have clean file system/etc

so basically, you still use shell scripts to create a docker image, using dockerfile is pain, just use gloden image for the most times.