Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
588 views
in Technique[技术] by (71.8m points)

dockerfile - Install python package in docker file

In my docker file, I want to install med2image python package (https://github.com/FNNDSC/med2image). I use the following code:

FROM ubuntu:16.04
RUN apt-get update && apt-get install -y --no-install-recommends 
    python3.5 
    python3-pip 
    && 
apt-get clean && 
rm -rf /var/lib/apt/lists/*
RUN pip install nibabel pydicom matplotlib pillow
RUN pip install med2image

But I get the following error when I want to build the image:

Downloading https://files.pythonhosted.org/packages/6f/e5/948b023c7feb72adf7dfb26d90a13c838737bbf52be704f5ddd0878e3264/med2image-1.1.2.tar.gz
Complete output from command python setup.py egg_info:
Sorry, only Python 3.5+ is supported.

----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in  /tmp/pip-install-FnNb_S/med2image/
The command '/bin/sh -c pip install med2image' returned a non-zero code: 1

What should I do?!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Recommended base image

As suggested in my comment, you could write a Dockerfile that looks like:

FROM python:3

RUN pip install --no-cache-dir --upgrade pip && 
    pip install --no-cache-dir nibabel pydicom matplotlib pillow && 
    pip install --no-cache-dir med2image

CMD ["cat", "/etc/os-release"]

And the command example above could confirm at runtime (docker build --pull -t test . && docker run --rm -it test) that this image is based on the GNU/Linux distribution "Debian stable".

Generic Dockerfile template

Finally to give a comprehensive answer, note that a good practice regarding Python dependencies consists in specifying them in a declarative way in a dedicated text file (in alphabetical order, to ease review and update) so that for your example, you may want to write the following file:

requirements.txt

matplotlib
med2image
nibabel
pillow
pydicom

and use the following generic Dockerfile

FROM python:3

WORKDIR /usr/src/app

COPY requirements.txt ./

RUN pip install --no-cache-dir --upgrade pip && 
    pip install --no-cache-dir -r requirements.txt

COPY . .

CMD [ "python", "./your-daemon-or-script.py" ]

To be more precise, this is the approach suggested in the documentation of the Docker official image python, §. How to use this image


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...