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 med2image
# Note: we had to merge the two "pip install" package lists here, otherwise
# the last "pip install" command in the OP may break dependency resolution…
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
» pip install docker
How to run python package inside a Docker container?
Setting up the docker module in Python
Installing a new python package for an existing container
How to install a python module in a docker container - Stack Overflow
Videos
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 med2image
# Note: we had to merge the two "pip install" package lists here, otherwise
# the last "pip install" command in the OP may break dependency resolution…
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
Some of the other answers/comments are suggesting to change your base image but if you want to keep your ubuntu 16.04 you can also simply specify your version of pip/python to use pip3 or pip3.5 like shown below.
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 pip3 install nibabel pydicom matplotlib pillow
RUN pip3 install med2image
Hi. Could anyone help explain to me how to actually setup the docker module in python. I have tried so far:
pip install docker
However, after doing this, I try running the basic script:
import docker
client = docker.from_env()
After doing so, I get the following:
Exception has occurred: ModuleNotFoundError
No module named 'docker'
Could anyone please explain to me when I am getting this message. It's really confusing. Apologies if this is very obvious
» pip install docker-py
I am new to docker and playing around to replace my python virtual environment for my r/django development.
I have followed this guide to both set up the container and a django project.
That guide sets up a Dockerfile which installs the python packages defined in requirements.txt.
Suppose now after doing some development on the django project that I find I need a new python package. I can install it by running:
docker exec -it 1c7cfa468346 pip install [packageName]
but I found that after stopping and restarting the container, the package is gone. So it appears I need to build a new image entirely (I don't fully grasp the vocabulary yet....). But it appears that images are immutable, so I CAN'T change the existing image. So I have to rebuild the whole thing entirely? Following the guide that would mean to run:
sudo docker compose run web django-admin startproject [DjangoAppName] .
again. BUT that would overwrite the already existing app, no? I don't want to startproject again...
What is the correct way to add a new python package to my docker development environment without losing existing files?
You can get bash from your container with this command:
docker-compose exec freqtrade bash
and then:
pip install finta
OR run only one command:
docker-compose exec freqtrade pip install finta
If the above solutions didn't work, You can run docker ps command and get container id of your container. Then
docker exec -it CONTAINER_ID bash
pip install finta
You need to make your own docker image that has finta installed. Luckily you can build on top of the standard freqtrade docker image.
First make a Dockerfile with these two lines in it
FROM freqtradeorg/freqtrade:stable
RUN pip install finta
Then build the image (calling the new image myfreqtrade) by running the command
docker build -t myfreqtrade .
Finally change the docker-compose.yml file to run your image by changing the line
image: freqtradeorg/freqtrade:stable
to
image: myfreqtrade
And that should be that.
» pip install python-docker