FROM python:3.7.4-alpine3.9
ENV PYTHONDONTWRITEBYTECODE=1
ENV PYTHONUNBUFFERED=1
WORKDIR /app
RUN apk update && apk upgrade
RUN apk add --no-cache linux-headers bash gcc \
musl-dev libjpeg-turbo-dev libpng libpq \
postgresql-dev git zlib-dev libmagic \
python-dev libffi-dev openssl-dev py2-pip
COPY ./requirements.txt /app
RUN pip install -U pip
RUN pip install -U -r /app/requirements.txt
COPY ./ /app
FROM nginx:1.17.1-alpine
RUN rm /etc/nginx/conf.d/default.conf
COPY default.conf /etc/nginx/conf.d
server {
listen 5000;
client_max_body_size 10M;
location / {
proxy_pass http://app:5000;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $host;
proxy_redirect off;
}
location /static/ {
alias /app/staticfiles/;
}
location /media/ {
alias /srv/media/;
}
}
version: '3'
services:
app:
restart: always
build: ./
command: ./docker-entrypoint.stage.sh
env_file:
- env-stage.env
volumes:
- static_volume:/app/staticfiles
- /srv/media:/app/media:rw
expose:
- 5000
nginx:
restart: always
build: ./nginx
volumes:
- static_volume:/app/staticfiles
- /srv/media:/srv/media:ro
ports:
- 5000:5000
depends_on:
- app
volumes:
static_volume:
#!/usr/bin/env bash
# clean static
rm -fr staticfiles
python3 manage.py collectstatic --noinput
python3 manage.py migrate --noinput
# Probably gunicorn for you
daphne -b 0.0.0.0 -p 5000 secpim.asgi:application # Python asgi/wsgi path
Depends on what your django app needs...
DJANGO_SETTINGS_MODULE=django_project_name.settings.stage <-- python path
SECRET_KEY=
SQL_ENGINE=django.db.backends.postgresql
SQL_DATABASE=blah
SQL_USER=blah
SQL_PASSWORD=blah.
SQL_HOST=
SQL_PORT=
version: '3'
services:
db:
restart: always
image: postgres:11.3-alpine
environment:
POSTGRES_DB: blah
POSTGRES_USER: blah
POSTGRES_PASSWORD: blah
volumes:
- postgres:/var/lib/postgresql/data
app:
restart: always
build: ./
command: ./docker-entrypoint.dev.sh
volumes:
- ./:/app:rw
depends_on:
- db
env_file:
- env-dev.env
ports:
- "5000:5000"
volumes:
postgres:
#!/usr/bin/env bash
echo "Waiting for postgres..."
while ! nc -z $SQL_HOST $SQL_PORT; do
sleep 0.1
done
echo "PostgreSQL started"
python3 manage.py makemigrations
python3 manage.py migrate
python3 manage.py runserver 0.0.0.0:5000