Skip to content

Instantly share code, notes, and snippets.

@wodCZ
Created February 4, 2018 14:38
Show Gist options
  • Save wodCZ/ee992e3ebcc75fe33e7029ad6b6c0af9 to your computer and use it in GitHub Desktop.
Save wodCZ/ee992e3ebcc75fe33e7029ad6b6c0af9 to your computer and use it in GitHub Desktop.
django, postgres, redis, celery, nginx, uwsgi docker setup
version: '2'
services:
web:
restart: always
image: example.com:5000/myapp/myapp-backend
env_file: env
expose:
- "8000"
links:
- db:db
- redis:redis
volumes:
- static:/code/static
- media:/code/media
depends_on:
- db
- redis
labels:
io.rancher.container.pull_image: 'always'
worker:
restart: always
image: rexample.com:5000/myapp/myapp-backend
env_file: env
links:
- db:db
- redis:redis
volumes:
- static:/code/static
- media:/code/media
depends_on:
- db
- redis
labels:
io.rancher.container.pull_image: 'always'
command: bash -c "/venv/bin/celery -A moyobo.celery worker -l info"
nginx:
restart: always
image: argo22/nginx-for-python
expose:
- "8000"
links:
- web:app
volumes:
- static:/code/static
- media:/code/media
depends_on:
- web
labels:
io.rancher.container.pull_image: 'always'
collectstatic:
restart: on-failure
image: example.com:5000/myapp/myapp-backend
env_file: env
command: bash -c "/venv/bin/python manage.py graphql_schema && /venv/bin/python manage.py collectstatic --no-input"
links:
- db:db
- redis:redis
volumes:
- static:/code/static
- media:/code/media
depends_on:
- db
labels:
io.rancher.container.start_once: 'true'
io.rancher.container.pull_image: 'always'
migrate:
restart: on-failure
image: example.com:5000/myapp/myapp-backend
env_file: env
command: /venv/bin/python manage.py migrate --no-input
links:
- db:db
- redis:redis
depends_on:
- db
labels:
io.rancher.container.start_once: 'true'
io.rancher.container.pull_image: 'always'
redis:
restart: always
image: redis:alpine
db:
restart: always
image: postgres:alpine
env_file:
- env
expose:
- "5432"
volumes:
- database:/var/lib/postgresql/data
volumes:
database:
static:
media:
FROM python:latest
ADD requirements.txt /requirements.txt
RUN python3.6 -m venv /venv \
&& /venv/bin/pip install -U pip \
&& LIBRARY_PATH=/lib:/usr/lib /bin/sh -c "/venv/bin/pip install --no-cache-dir -r /requirements.txt"
ENV PYTHONUNBUFFERED 1
# Copy your application code to the container (make sure you create a .dockerignore file if any large files or directories should be excluded)
RUN mkdir /code/
WORKDIR /code/
ADD . /code/
# uWSGI will listen on this port
EXPOSE 8000
# Add any custom, static environment variables needed by Django or your settings file here:
ENV DJANGO_SETTINGS_MODULE=myapp.settings
# uWSGI configuration (customize as needed):
ENV UWSGI_VIRTUALENV=/venv UWSGI_WSGI_FILE=myapp/wsgi.py UWSGI_HTTP=:8000 UWSGI_MASTER=1 UWSGI_WORKERS=2 UWSGI_THREADS=8 UWSGI_LAZY_APPS=1 UWSGI_WSGI_ENV_BEHAVIOR=holy
# Start uWSGI
CMD ["/venv/bin/uwsgi", "--http-auto-chunked", "--http-keepalive"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment