Skip to content

Commit acb709b

Browse files
Add Docker Dojango - Postgres
1 parent 5daac9a commit acb709b

File tree

17 files changed

+310
-0
lines changed

17 files changed

+310
-0
lines changed

Docker_Django/.env

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
DEBUG=1
2+
SECRET_KEY='django-insecure-+rjud+mt^+c*p-&#m5^m65m)$0$^$159h@#m0i4-n+ayp80xc+'
3+
4+
DJANGO_ALLOWED_HOSTS=localhost 127.0.0.1 [::1]
5+
6+
SQL_ENGINE=django.db.backends.postgresql
7+
SQL_DATABASE=hello_django_dev
8+
SQL_USER=hello_django
9+
SQL_PASSWORD=hello_django
10+
# SQL_HOST=db
11+
SQL_PORT=5432
12+
DATABASE=postgres

Docker_Django/app/Dockerfile

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# pull official base image
2+
FROM python:3.9.6-alpine
3+
4+
# set work directory
5+
WORKDIR /usr/src/app
6+
7+
# set environment variables
8+
ENV PYTHONDONTWRITEBYTECODE 1
9+
ENV PYTHONUNBUFFERED 1
10+
11+
# install psycopg2 dependencies
12+
RUN apk update \
13+
&& apk add postgresql-dev gcc python3-dev musl-dev
14+
15+
# install dependencies
16+
RUN pip install --upgrade pip
17+
COPY ./requirements.txt .
18+
RUN pip install -r requirements.txt
19+
20+
# copy entrypoint.sh
21+
COPY ./entrypoint.sh .
22+
RUN sed -i 's/\r$//g' /usr/src/app/entrypoint.sh
23+
RUN chmod +x /usr/src/app/entrypoint.sh
24+
25+
# copy project
26+
COPY . .
27+
28+
# run entrypoint.sh
29+
ENTRYPOINT ["/usr/src/app/entrypoint.sh"]

Docker_Django/app/db.sqlite3

128 KB
Binary file not shown.
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
version: '3.8'
2+
3+
services:
4+
# Browrser
5+
web:
6+
build: ../app
7+
command: python manage.py runserver 0.0.0.0:8001
8+
volumes:
9+
- ../app/:/usr/src/app/
10+
ports:
11+
- 8001:8001
12+
env_file:
13+
- ../.env
14+
depends_on:
15+
- db
16+
17+
# Postgres
18+
db:
19+
image: postgres:13.0-alpine
20+
volumes:
21+
- postgres_data:/var/lib/postgresql/data/
22+
environment:
23+
- POSTGRES_USER=hello_django
24+
- POSTGRES_PASSWORD=hello_django
25+
- POSTGRES_DB=hello_django_dev
26+
27+
volumes:
28+
postgres_data:

Docker_Django/app/entrypoint.sh

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#!/bin/sh
2+
3+
if [ "$DATABASE" = "postgres" ]
4+
then
5+
echo "Waiting for postgres..."
6+
7+
while ! nc -z $SQL_HOST $SQL_PORT; do
8+
sleep 0.1
9+
done
10+
11+
echo "PostgreSQL started"
12+
fi
13+
14+
python manage.py flush --no-input
15+
python manage.py migrate
16+
17+
exec "$@"

Docker_Django/app/hello_django/__init__.py

Whitespace-only changes.
144 Bytes
Binary file not shown.
Binary file not shown.
926 Bytes
Binary file not shown.
557 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)