-
Notifications
You must be signed in to change notification settings - Fork 0
/
Dockerfile
35 lines (30 loc) · 1.38 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
FROM python:3.7-alpine
LABEL maintainer="Farhan Arshad"
ENV PYTHONUNBUFFERED 1
COPY ./requirements.txt /requirements.txt
# It uses package manager comes with alpine nae 'apk' 'add' a package, and
# before this '--update' updates the registry but '--no-cache' don't store the
# registry index on the docker file to minimize the number of extra files and
# packages that are included in the docker container. so that docker container
# have smallest footprint(space occupied) and don't include extra dependencies
# which may cause unexpected effects and create security vulnerabilities in
# the system.
RUN apk add --update --no-cache postgresql-client
# Add some temporary packages and remove it after instaling the python
# requirements. '--virtual' is a alias for our dependencies so we can easily
# remove them. '.temp-build-deps' name of the alias that means we temporary
# build the dependencies.
RUN apk add --update --no-cache --virtual .temp-build-deps \
gcc libc-dev linux-headers postgresql-dev
RUN pip install -r /requirements.txt
# Remove all temporary added packages
RUN apk del .temp-build-deps
# create a new directory in docker image
RUN mkdir /src
WORKDIR /src
# Copy souce code of the project in the docker image
COPY ./src /src
# create a user name 'user', -D allow to run process from the project and limitize the user scope
RUN adduser -D user
# switch to new created user
USER user