# Dockerfile, Image, Container# Container with python version 3.10
FROM python:3.10# Add python file and directory
ADD main.py .# upgrade pip and install pip packages
RUN pip install --no-cache-dir--upgrade pip &&
pip install --no-cache-dir numpy
# 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...# run python program
CMD ["python","main.py"]
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"]
# install python
docker pull python
# run python in interactive mode with no persistent storage
docker run -it python
# run python in interactive mode and mount an absolute path# to a folder named shared in the python container for persistent storage
docker run -it -v /Users/codecaine/Desktop:/shared python
# run python in interactive mode and mount the terminal current working directory# to a folder named shared in the python container for persistent storage
docker run -it -v ${PWD}:/shared python
# create a volume named shared
volume to create my_volume
# get a list of volumes on system
docker volume ls
# to attach a volume for persistent storage in python
docker run -it -v my_volume:/shared python
# in python check the folderimport os
# change system directory to shared folder
os.chdir("shared")# list files in the current directory
os.listdir(".")# stop all active services - containers and mounted volumes
docker system prune
# remove a volume is storage is not needed anymore
docker volume rm my_volume