Dockerfile production/build/debug/test environment
The answer might be straightforward: just create 4 Dockerfile
s one depending on another.
You can add a volume to share build from sources part. The question is whether you want result assets to be included in the image or build it from sources each time.
Create 4 folders to have Dockerfile
in each.
Production
production/Dockefile
:
FROM # put server hereCOPY # put config here# some other option# volume sharing?
Build
build/Dockerfile
:
# install dependenciesADD # add sources hereRUN # some building script
Debug
debug/Dockefile
:
# ideally, configure production or build image
Test
test/Dockefile
:
FROM # import production# install test dependenciesRUN # test runner
There are also several options.1. Use .gitignore with negative pattern (or ADD?)
*!directory-i-want-to-add!another-directory-i-want-to-add
Plus use docker command specifying dockerfiles and context:
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 .
You could also use different gitignore files.
- Mount volumesSkip sending context at all, just use mounting volumes during run time (using
-v host-dir:/docker-dir
).
So you'd have to:
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 dirdocker build -t my/serve-image -f docker-serve . # build production from output dirdocker run my/serve-image # production-like serving from included or mounted dirdocker build -t my/serve-image -f docker-debug . # build debug from output dirdocker run my/serve-image # debug-like serving (uses build-image with some watch magic)