Docker: 如何管理开发和生产设置?

Docker: how to manage development and production settings?

我才刚刚开始 Docker。在我的 OSX 开发机器上使用官方 NGINX 映像(使用 Docker 机器作为 Docker 主机)我 运行 对抗 sendfile 和 VirtualBox 的错误表示服务器无法显示我对文件所做的更改。

解决方法是使用修改后的 nginx.conf 文件关闭 sendfileThis guy's solution has an instruction in the Dockerfile to copy a customised conf file into the container. Alternatively, this guy 将 NGINX 配置映射到具有修改后的 conf 文件的新文件夹。

这种东西在本地运行正常。但是如果我的云主机上不需要这个修改呢?在部署时我应该如何处理这个和其他差异?

您可以通过例如将自定义 nginx.conf 安装到 development 中的容器中--volume ./nginx/nginx.conf:/etc/nginx/nginx.conf 并在 production.

中将此参数省略到 docker run

如果使用 docker-compose,我推荐的两个选项是: