Dockerfile,如何创build图像的Ubuntu 14.04
昨天我已经被问及如何使用dockerfile制作docker镜像
这一次我想添加一个问题
如果我想在操作系统的Ubuntu 14:04 docker安装它,postgresql-9.3.10,安装Java JDK 6,复制文件(重要的位置),并在图像上创build一个用户。
我是否可以根据需要为图像组合多个dockerfile? (postgresql的dockerfile,java,copyfile,并创build一个用户,所以一个dockerfile)
例。 我做了一个包含命令的dockerfile“ubuntu”
顶线
# Create dockerfile # get OS ubuntu to images FROM ubuntu: 14:04 # !!further adding a command on the following link, below the line per-dockerfile(intends command in dockerfile on the link) # command on dockerfile postgresql-9.3 https://github.com/docker-library/postgres/blob/ed23320582f4ec5b0e5e35c99d98966dacbc6ed8/9.3/Dockerfile # command on dockerfile java https://github.com/docker-library/java/blob/master/openjdk-6-jdk/Dockerfile # create a user on images ubuntu RUN adduser myuser # copy file/directory on images ubuntu COPY /home/myuser/test /home/userimagedockerubuntu/test # ? CMD ["ubuntu:14.04"]
请帮帮我
不,你不能合并多个Dockerfile。
最好的做法是:
-
从imabe开始已经包含了你需要的东西,就像这个基于Ubuntu的postgresql镜像一样。
这意味着如果你的Dockerfile开始于:FROM orchardup/postgresql
你将会构build一个已经包含ubuntu和postgresql的图像。
-
COPY
或RUN
你需要在你的dockerfile, 像openjdk6 :RUN \ apt-get update && \ apt-get install -y openjdk-6-jdk && \ rm -rf /var/lib/apt/lists/* ENV JAVA_HOME /usr/lib/jvm/java-6-openjdk-amd64
最后,你的默认命令应该运行你想要的服务:
# Set the default command to run when starting the container CMD ["/usr/lib/postgresql/9.3/bin/postgres", "-D", "/var/lib/postgresql/9.3/main", "-c", "config_file=/etc/postgresql/9.3/main/postgresql.conf"]
但是由于orchardup/postgresql
的orchardup/postgresql
已经包含了一个CMD
,所以你甚至不需要指定一个:你将inheritance自你的基础镜像中定义的CMD
。
我认为嵌套多个Dockerfiles是不可能的,由于图层系统。 然而,你可以将任务外包给shell脚本,并在Dockerfile中运行这些脚本。
在您的Dockerfile中,请修复基本映像:
FROM ubuntu:14.04
此外您的CMD
无效。 你可能想要用CMD ["bash"]
执行一个你可以使用的bash。
我build议你从Dockerfile的文档开始,因为你明显错过了这个,它包含了所有你的问题的答案,甚至你甚至不想问的问题。