Created
February 16, 2018 22:13
-
-
Save sgentile/126f8ebccd1e09299aab3618f2e2b732 to your computer and use it in GitHub Desktop.
django-postgres-docker-docker-compose
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
version: "2.2" | |
services: | |
web: | |
build: . | |
ports: | |
- "8080:8080" | |
depends_on: | |
- "db" | |
db: | |
image: postgres:9.6-alpine | |
ports: | |
- "5342:5342" | |
environment: | |
POSTGRES_USER: "postgres" | |
POSTGRES_PASSWORD: "mysecretpassword" | |
POSTGRES_DB: "polls" | |
volumes: | |
- ./data/postgres:/var/lib/postgresql/data | |
================ | |
web docker file | |
FROM python:3.6.4 | |
ENV PYTHONBUFFERED 1 | |
ENV PROJECT=mysite | |
ENV CONTAINER_HOME=/app | |
ENV CONTAINER_PROJECT=${CONTAINER_HOME}/${PROJECT} | |
WORKDIR ${CONTAINER_HOME} | |
RUN mkdir logs | |
COPY . ${CONTAINER_PROJECT} | |
RUN pip install -r ${CONTAINER_PROJECT}/requirements.txt \ | |
&& pip install gunicorn | |
EXPOSE 8080 | |
WORKDIR ${CONTAINER_PROJECT} | |
COPY ./entrypoint.sh / | |
ENTRYPOINT [ "/entrypoint.sh" ] | |
# build | |
# docker build -t django_gunicorn:v1 . | |
# run | |
# docker run --restart=always -p 8000:8000 -it django_gunicorn:v1 | |
========= | |
#!/bin/bash | |
# touch ./logs/gunicorn.log | |
# touch ./logs/gunicorn-access.log | |
# tail -n 0 -f ./logs/gunicorn*.log & | |
export DJANGO_SETTINGS_MODULE=mysite.settings | |
cd mysite | |
# python manage.py migrate | |
exec gunicorn mysite.wsgi:application \ | |
--name mysite_django \ | |
--bind 0.0.0.0:8080 | |
--workers=5 \ | |
--log-level=info \ | |
--log-file=./logs/gunicorn.log \ | |
--access-logfile=./logs/gunicorn-access.log \ | |
"$@" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment