想象一下,你有你的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