-
Notifications
You must be signed in to change notification settings - Fork 0
/
Dockerfile
63 lines (49 loc) · 1.54 KB
/
Dockerfile
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# SPDX-FileCopyrightText: 2023 The Template-Sandbox Authors
#
# SPDX-License-Identifier: Apache-2.0
# Set the working directory to all stages
ARG WORKDIR="/app"
# Stage 1: Build from python 3.9
FROM python:3.11-slim AS builder
# Activate argument
ARG WORKDIR
# Do not buffer stdout:
ENV PYTHONUNBUFFERED=1
# Do not create .pyc files:
ENV PYTHONDONTWRITEBYTECODE=1
# Install poetry with project-specific virtual environment (good practice)
RUN pip install poetry && poetry config virtualenvs.in-project true
# Change directory
WORKDIR ${WORKDIR}
# Copy all the project into the container (except those in .dockerignore)
COPY . .
# Install the project using poetry
RUN poetry install --only main
# Stage 2: running app with python 3.9
FROM python:3.11-alpine
# Activate argument
ARG WORKDIR
# Change directory
WORKDIR ${WORKDIR}
# Copy the result from the builder container
COPY --from=builder ${WORKDIR} .
# As good practice, create a user for the application
# For options, see https://boxmatrix.info/wiki/Property:adduser
# -D: no password
# -H: no default home
# -h: use this as home
# -u: use this UID
RUN adduser app -DHh ${WORKDIR} -u 1000
# Switch to this user
USER 1000
# Run some script
CMD [ "./.venv/bin/python", "-c", "import template_sandbox.greeter as gt; gt.main()" ]
#
# Can also use entry points
# ENTRYPOINT ["./.venv/bin/python", "-i"]
# Exposing ports, you can use docker run -p 8182:8000 [...] to map the port 8182
# of the host to the container's 8000
# EXPOSE 8000
#
# Run a simple web server
# CMD [ "./.venv/bin/python", "-m", "http.server" ]