Create / Build / Debug / Dockerfile Test Environment

Imagine that you have your web application and some workflow performers:

  • http server (servicing pre-build asset files) - production
  • builder (compiling / combining js / css / html from sources) - deployment / development
  • debugger / builder (from sources on the fly, add js source maps) - development
  • selenium (current tests) - integration testing

How can we build multi-level images to make those workflow performers work most efficiently? In fact, I mean "run the fastest and write the least."

+3
source share
1 answer

The answer may be simple: just create 4 Dockerfileone depending on the other.

You can add a volume to share the assembly from part of the source. The question is whether you want the assets of the result to be included in the image or each time to create it from sources.

Create 4 folders to have Dockerfilein each.

Products

production/Dockefile:

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

Build

build/Dockerfile:

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

Debug

debug/Dockefile:

# ideally, configure production or build image

Test

test/Dockefile:

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

There are also several options. 1. Use a negative .gitignore (or ADD?)

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

Plus, use the docker command that defines the 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 can also use different gitignore files.

  1. Mount Volumes Skip the send context, just use the install volumes at runtime (using -v host-dir:/docker-dir).

So you need 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 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)
+1

All Articles