想象一下,你有你的Web应用程序和一些工作流程执行者:Dockerfile生产/建设/调试/测试环境
- HTTP服务器(服务预构建资源文件) - 生产
- 建设者(编译/捆扎部署/开发
- 调试器/生成器(从上飞源建设,增加JS源地图) - - 发展
- 硒(运行测试) - JS/CSS /来源)HTML集成测试
我们如何构建分层的图像以使这些工作流执行者最有效地工作?我的意思是“跑得最快,写得最少”。
想象一下,你有你的Web应用程序和一些工作流程执行者:Dockerfile生产/建设/调试/测试环境
我们如何构建分层的图像以使这些工作流执行者最有效地工作?我的意思是“跑得最快,写得最少”。
答案可能很简单:只需创建4个Dockerfile
即可。
您可以添加一个卷以从源部分共享构建。问题是你想要结果资产包含在图像中还是每次都从源代码构建。
创建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与阴模(或补充吗?)
*
!directory-i-want-to-add
!another-directory-i-want-to-add
加上使用泊坞窗命令指定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文件。
-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)
这可能不适用于所有测试运行者/调试器/构建者,但这是我们应该争取的理想选择。恕我直言。 – Vanuan
好吧,这里还有单元测试,但是这可能是另外一个。 – Vanuan
这不是重复的:http://stackoverflow.com/questions/28169098/dockerfile-and-dev-test-prod-environment 它略有不同。这是一个更一般的。 – Vanuan