Whats the best way to avoid polluting containers with build dependencies ? (devel packages etc)


I want to build a python interpreter in one container, then use the results of that build in other containers.

To build my python I need to install various build time dependencies. Most of these are devel packages. I do not want them in my run time.

Using from:python-builder in my docker file means I have to think about manually clearing out the dependencies after the build (of the python) has completed. I have two issues with this:

  1. I don’t really trust that it can be done reliably
  2. I don’t want the graph of my containers to be dictated by needing a python interpreter build.

I’d really like to treat the python-builder as a kind of “mixin”, and consume the data from its “output” volume using volumes-from. But volumes from can’t be used in the Dockerfile

(see https://github.com/docker/docker/issues/3949)

Are there established ways of dealing with this ? (Other than the obvious wrapping with scripts and using --volumes-from on the command line)

Bump, anyone ? Any guidance appreciated.

I did the following in the end.

  1. Make an image (python-builder) whose docker file builds the basic python interpreter and installs it in the intended path. The *-devel packages are retained. The python build follows this guide: http://blog.dscpl.com.au/2015/06/installing-custom-python-version-into.html
  2. Include in the image a script for each ‘flavour’ of python needed.
  3. images which need to include a flavour of this python have a build script like this:

docker run --name=appx-python -i -v $(pwd)/host:/host $REPO_ADDRESS/python-builder:latest << EOF
/tmp/buildfor-appx.sh && cp /build/python-builder/* /host/
docker build --force-rm=true -t $REPO_ADDRESS/appx:latest .

buildfor-appx.sh installs some additional packages into the python installation and tars up the result to /build/python-builder/

The Dockerfile for appx does an ADD host/Python-appx.tar.gz /

If I really want devel packages I simply compile it outside docker and in Dockerfile COPY the binary file into image.
I don’t know whether this is practical for you.