-
Notifications
You must be signed in to change notification settings - Fork 82
/
Dockerfile-python
27 lines (21 loc) · 765 Bytes
/
Dockerfile-python
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# https://hub.docker.com/_/python
# https://stackoverflow.com/questions/48561981/activate-python-virtualenv-in-dockerfile
# First stage is the builder or compiler
FROM python:3.8-slim as compiler
ENV PYTHONUNBUFFERED 1
WORKDIR /app
RUN python -m venv /opt/venv
# Enable venv
ENV PATH="/opt/venv/bin:$PATH"
COPY ./requirements.txt /app/requirements.txt
RUN pip install --no-cache-dir --upgrade --requirement requirements.txt
# First stage is the runner
FROM python:3.8-slim as runner
WORKDIR /app
COPY --from=compiler /opt/venv /opt/venv
# Enable venv
ENV PATH="/opt/venv/bin:$PATH"
COPY . /app/
# This is used instead of 'entrypoint' in docker-compose.yml.
# Note: The stackoverflow answers state virtualenv is not needed most of the time.
CMD ["/bin/bash" ]