# Make sure all layers are based on the same python version. FROM python:3.10-slim-buster as base # The actual dev/test image. # This is where you can install additional dev/test requirements. FROM base as test COPY ./requirements_test.txt /code/requirements_test.txt RUN python -m pip install --no-cache-dir --upgrade -r /code/requirements_test.txt ENTRYPOINT ["python"] # Assuming you run tests using pytest. CMD ["-m", "pytest", "..."] # The actual production image. FROM base as runtime COPY ./requirements.txt /code/requirements.txt RUN python -m pip install --no-cache-dir --upgrade -r /code/requirements.txt ENTRYPOINT ["python"] # Assuming you wantto run main.py as a script. CMD ["/path/to/main.py"]
-r requirements.txt pytest
services: service: build: context: . dockerfile: ./Dockerfile target: runtime # or test for running tests
# This requires to mount the file 'requirements_dev.txt' into the container - as a volume. docker exec -it
python -m pip install --upgrade -r requirements_dev.txt
FROM AppBase:v1.2 ...