csmith49 csmith49 - 4 years ago 154
Python Question

Get python project into docker image

I'm new to python. I have a maven project which uses the org.jolokia maven-docker-plugin to create a docker image that consumes a python library called Talon.

Currently the container uses a script which executes (along with other pre-requisites):

pip install talon==1.2.6

I have forked the Talon project and made some changes. Now I would like my docker container to consume MY version of Talon. How can I do this?

What I have tried:

  1. Copied my changed python file to overwrite the original
    file after the pip install above (via mount directory into container) (seems a no-no).

  2. Created tar of entire Talon project, added it into image, replaced with
    pip install /maven/talon.tar.gz
    to the above script (didn't work).

  3. Added entire Talon project directory as maven fileset and replaced above script with
    python /maven/talon/setup.py install

Any help much appreciated!

Answer Source

The way to do this is to get your python project into the image and run install on the setup.py. This method assumes your image already has the python interpreter and the relevant dependencies installed for your project to run.

Copy your python project code into a folder in your maven project i.e. one called input.

Use fileSets in the assembly of the image to assemble the python source code into the image. <directory> should point to the input folder containing your python source code:


Then you want a script to run python setup.py install from the output directory (/maven/output/mypythonproject).

I.e. use a runCmd:

        cd /maven/output/mypythonproject \
        python setup.py install

This installs the python module and puts egg file in the /usr/local/lib/python27/dist-packages folder, which will be found by your python interpreter.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download