-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathDockerfile
More file actions
36 lines (28 loc) · 1.07 KB
/
Dockerfile
File metadata and controls
36 lines (28 loc) · 1.07 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
FROM python:3.9.2-slim
RUN set -eux; \
groupadd -r postgres --gid=999; \
useradd -r -g postgres --uid=999 --home-dir=/var/lib/postgresql --shell=/bin/bash postgres; \
mkdir -p /var/lib/postgresql; \
chown -R postgres:postgres /var/lib/postgresql
RUN mkdir -p /var/run/postgresql && chown -R postgres:postgres /var/run/postgresql && chmod 2777 /var/run/postgresql
RUN apt-get update \
&& apt-get install -y --no-install-recommends postgresql build-essential libpq-dev python-psycopg2 gcc \
&& apt-get purge -y --auto-remove \
&& rm -rf /var/lib/apt/lists/*
# Environment variables
ENV DB_USER='test'
ENV DB_PASSWORD='test123'
ENV DB_NAME='testdb'
ENV DB_HOST='127.0.0.1'
ENV DB_PORT='5432'
# Create DB and User
USER postgres
RUN service postgresql start \
&& psql -c "CREATE USER ${DB_USER} WITH SUPERUSER PASSWORD '${DB_PASSWORD}';ALTER USER ${DB_USER} CREATEDB;" \
&& psql -c "CREATE DATABASE ${DB_NAME} WITH owner ${DB_USER} encoding 'utf-8'"
USER root
COPY ./scripts /
#Install psycopg2
RUN pip install psycopg2-binary
RUN chmod +x /entrypoint.sh
ENTRYPOINT ["/entrypoint.sh"]