-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathDockerfile.dev
More file actions
59 lines (46 loc) · 1.43 KB
/
Dockerfile.dev
File metadata and controls
59 lines (46 loc) · 1.43 KB
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
# Stage 01: Build
ARG IMAGE_TAG=latest
FROM ubuntu:$IMAGE_TAG AS builder
# Labels for docker image
LABEL maintainer="Anupam Yadav"
LABEL email="anupaminit@gmail.com"
ARG USERNAME=python
ARG GROUPNAME=$USERNAME
ARG USERID=1100
ARG GROUPID=$USERID
# Check the current user and create a new user
RUN whoami
RUN groupadd --gid $GROUPID $GROUPNAME && useradd --uid $USERID --gid $GROUPID -m $USERNAME
# Install the tools required for the project
RUN apt-get update && apt-get install -y \
python3 \
python3-pip \
python3-venv
# Copy requirements file and install all the required python packages
WORKDIR /app
COPY python/requirements.txt /app
# RUN pip3 install --no-cache-dir --break-system-packages -r requirements.txt
RUN python3 -m venv appenv \
&& . appenv/bin/activate \
&& pip install --no-cache-dir -r requirements.txt
# Stage 02: Run
FROM python:3.10-slim
ARG USERNAME=python
ARG GROUPNAME=$USERNAME
ARG USERID=1100
ARG GROUPID=$USERID
# Check the current user and create a new user
RUN whoami
RUN groupadd --gid $GROUPID $GROUPNAME && useradd --uid $USERID --gid $GROUPID -m $USERNAME
# Switch to project directory and copy required files
WORKDIR /app
COPY --from=builder /app .
COPY python /app
RUN . appenv/bin/activate
# Change the user to newly created user
USER $USERNAME
RUN whoami
# Expose the container port
EXPOSE 4999
# Run the main application file on container startup in python's venv
CMD ["appenv/bin/python", "run.py"]