Skip to content

Instantly share code, notes, and snippets.

@mmerickel
Last active December 19, 2015 12:49
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mmerickel/5957973 to your computer and use it in GitHub Desktop.
Save mmerickel/5957973 to your computer and use it in GitHub Desktop.
A workflow for docker that separates build-time dependencies from run-time dependencies.

A workflow for docker that separates build-time dependencies from run-time dependencies.

Create the image used for building apps.

docker build -t pybuilder pybuilder

Create the image used for running apps.

Note

This step is unnecessary if you don't mind having build dependencies installed in your production system

docker build -t pyrunner pyrunner

Install application, leaving the constructed virtualenv in /venv and the application source in /app.

BUILD_ID=$(docker run -v /venv -v /app pybuilder /usr/local/bin/buildapp $URL)

Generate a new runner containing the built volumes. The new container contains the built products from the builder.

RUNNER_ID=(docker run -d -volumes-from $BUILD_ID pyrunner /bin/true)

If we are using the same docker instance for everything then we can simply commit the container and then run a bunch of them.

docker commit $RUNNER_ID pyramid_demo

However, if we want to redistribute the container to other docker instances then we can package the container into a tarball.

NOW=$(date +"%Y%m%d_%H%M%S")
docker export $RUNNER_ID | gzip > pyramid_demo.$NOW.tar.gz

From here we can redistribute the image and import it into other docker instances.

zcat pyramid_demo.$NOW.tar.gz | docker import - pyramid_demo

In both cases we now have an image with the pyramid_demo tag in docker. Now we can run the image as many times as we want.

APP_ID=$(docker run -d pyramid_demo /usr/local/bin/runapp)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment