举个例子:
Dockerfile for container1 :
FROM ubuntu:14.04
RUN apt-get update
RUN apt-get install -y php5 php5-mysql
Dockerfile for container2 :
FROM ubuntu:14.04
RUN apt-get update
RUN apt-get install -y php5 php5-mysql php5-dev php5-gd php5-memcache
php5-pspell
所以需要避免,
FROM ubuntu:14.04
RUN apt-get update
RUN apt-get install -y php5 php5-mysql
因为这是两个 Dockerfile 中的相同配置。
最佳答案
查看多阶段构建:https://docs.docker.com/develop/develop-images/multistage-build/
你的例子会变成:
FROM ubuntu:14.04 as image1
RUN apt-get update
RUN apt-get install -y php5 php5-mysql
FROM image1 as image2
RUN apt-get install -y php5-dev php5-gd php5-memcache php5-pspell
您的构建命令需要使用 --target
标志指定构建目标。
关于docker - 是否可以为具有相同配置的多个容器制作通用的 dockerfile?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50699026/