Docker Community Forums

Share and learn in the Docker community.

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

(Robinbryce) #1


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


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

(Robinbryce) #2

Bump, anyone ? Any guidance appreciated.

(Robinbryce) #3

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:
  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/ && cp /build/python-builder/* /host/
docker build --force-rm=true -t $REPO_ADDRESS/appx:latest . 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 /

(Jokies) #4

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.