xxxxxxxxxx
# syntax=docker/dockerfile:1
FROM python:3
ENV PYTHONDONTWRITEBYTECODE=1
ENV PYTHONUNBUFFERED=1
WORKDIR /code
COPY requirements.txt /code/
RUN pip install -r requirements.txt
COPY . /code/
xxxxxxxxxx
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"]
xxxxxxxxxx
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
xxxxxxxxxx
#Deriving the latest base image
FROM python:latest
#Labels as key value pair
LABEL Maintainer="roushan.me17"
# Any working directory can be chosen as per choice like '/' or '/home' etc
# i have chosen /usr/app/src
WORKDIR /usr/app/src
#to COPY the remote file at working directory in container
COPY test.py ./
# Now the structure looks like this '/usr/app/src/test.py'
#CMD instruction should be used to run the software
#contained by your image, along with any arguments.
CMD [ "python", "./test.py"]
xxxxxxxxxx
# Python
FROM ubuntu:18.04
ARG PYTHON_VERSION=3.9.1
ENV DEBIAN_FRONTEND=noninteractive
ENV PATH $PATH:/usr/local/bin
RUN --mount=type=cache,target=/var/cache/apt,sharing=locked,id=aptcache1804 --mount=type=cache,target=/var/lib/apt,sharing=locked,id=aptcache1804 \
export DEBIAN_FRONTEND=noninteractive \
&& apt-get update -y \
&& apt-get install -y apt-utils sudo wget tar
RUN --mount=type=cache,target=/var/cache/apt,sharing=locked,id=aptcache1804 --mount=type=cache,target=/var/lib/apt,sharing=locked,id=aptcache1804 \
export DEBIAN_FRONTEND=noninteractive \
&& apt-get update -y \
&& apt-get install -y build-essential zlib1g-dev libncurses5-dev libgdbm-dev libnss3-dev libssl-dev libsqlite3-dev libreadline-dev libffi-dev curl libbz2-dev
RUN wget https://www.python.org/ftp/python/${PYTHON_VERSION}/Python-${PYTHON_VERSION}.tgz \
&& tar -xf Python-${PYTHON_VERSION}.tgz
RUN cd Python-${PYTHON_VERSION} \
&& ls -la \
&& ./configure --enable-optimizations \
&& make -j 4 \
&& make altinstall
RUN pip3 install requests asyncio
COPY ./entrypoint.py ./entrypoint.py
ENTRYPOINT python ./entrypoint.py