【问题标题】:Dockerfile production/build/debug/test environmentDockerfile 生产/构建/调试/测试环境
【发布时间】:2016-06-14 11:25:54
【问题描述】:

假设您有自己的 Web 应用程序和一些工作流执行器:

  • http-server(提供预构建资产文件)- 生产
  • 构建器(从源代码编译/捆绑 js/css/html)- 部署/开发
  • 调试器/构建器(即时从源构建,添加 js 源映射)- 开发
  • selenium(运行测试)- 集成测试

我们如何构建分层图像以使这些工作流执行器最有效地工作?实际上,我的意思是“跑得最快,写得最少”。

【问题讨论】:

标签: docker development-environment production-environment dockerfile test-environments


【解决方案1】:

答案可能很简单:只需根据另一个创建 4 个Dockerfiles。

您可以添加一个卷以从源部分共享构建。问题是您是希望结果资产包含在图像中还是每次都从源构建它。

创建 4 个文件夹,每个文件夹中都有 Dockerfile

生产

production/Dockefile:

FROM  # put server here
COPY  # put config here
# some other option
# volume sharing?

构建

build/Dockerfile:

# install dependencies
ADD # add sources here
RUN # some building script

调试

debug/Dockefile:

# ideally, configure production or build image

测试

test/Dockefile:

FROM # import production
# install test dependencies
RUN # test runner

还有几个选项。 1. 使用带有否定模式的 .gitignore(或 ADD?)

*
!directory-i-want-to-add
!another-directory-i-want-to-add

另外使用 docker 命令指定 dockerfiles 和上下文:

docker build -t my/debug-image -f docker-debug .
docker build -t my/serve-image -f docker-serve .
docker build -t my/build-image -f docker-build .
docker build -t my/test-image -f docker-test .

你也可以使用不同的 gitignore 文件。

  1. 装载卷 完全跳过发送上下文,只需在运行时使用安装卷(使用-v host-dir:/docker-dir)。

所以你必须:

docker build -t my/build-image -f docker-build . # build `build` image (devtools like gulp, grunt, bundle, npm, etc)
docker run -v output:/output my/build-image build-command # copies files to output dir
docker build -t my/serve-image -f docker-serve . # build production from output dir
docker run my/serve-image # production-like serving from included or mounted dir
docker build -t my/serve-image -f docker-debug . # build debug from output dir
docker run my/serve-image # debug-like serving (uses build-image with some watch magic)

【讨论】:

  • 这可能不适用于所有测试运行器/调试器/构建器,但这是我们应该努力争取的理想。恕我直言。
猜你喜欢
  • 2011-01-05
  • 2016-08-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-11-05
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多