docker - 是否可以为具有相同配置的多个容器制作通用 dockerfile?
问题描述
让我们举个例子:
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
标志指定构建目标。
推荐阅读
- sample - 如何在 Android Studio 中测试示例代码(DownloadableFonts)?
- swift - 即使 firebase 检索仍未完成,代码仍会继续执行
- sql - 连接 SQL Server 中多行的字符串
- java - 'org.springframework.kafka.core.ConsumerFactory' 找不到
- oracle - Oracle 如何使用“connect by rownum <= n”评估分层查询
- javascript - 我无法通过 fetch API 在客户端从服务器(node.js + express)获取数据
- vue.js - Vue.js 递归和可编辑组件
- sql - 无法使用 System.Data.SqlClient 在 SQL Server 中创建多个用户定义的函数
- python - 尝试使用 python 重构静态站点的代码
- xamarin - 无法将 Visual Studio 连接到 Mac