Skip to content

Instantly share code, notes, and snippets.

@dguaraglia
Last active March 2, 2021 06:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dguaraglia/55e9b67c2c0e1f94cc6b7975819ef49b to your computer and use it in GitHub Desktop.
Save dguaraglia/55e9b67c2c0e1f94cc6b7975819ef49b to your computer and use it in GitHub Desktop.
version: "3.4"
services:
postgres:
user: "${UID}:${GID}"
image: postgres:9.6.18-alpine
expose:
- "5432"
ports:
- "5432:5432"
volumes:
- .development_db:/db
environment:
POSTGRES_PASSWORD: password
POSTGRES_USER: user
POSTGRES_DB: dbname
PGDATA: /db
redis:
image: "redis:alpine"
ports:
- "6379"
web:
restart: on-failure
user: "${UID}:${GID}"
build:
context: .
target: development
environment:
DATABASE_URL: "postgresql://user:password@postgres:5432/dbname"
REDIS_CACHE_LOCATION: "redis://redis:6379/1"
volumes:
- .:/app
ports:
- "8000:8000"
depends_on:
- postgres
- redis
# Runtime images
FROM python:3.8.8-slim as runtime
EXPOSE 8000
COPY . /app/
RUN mkdir -p /app/static/js
WORKDIR /app
RUN pip install -r requirements.txt
RUN python manage.py collectstatic --no-input --no-color
CMD gunicorn crohn.wsgi:application -w 2 -b :8000
FROM runtime as development
CMD 'bash -c "pip install -r requirements.txt && python manage.py migrate && python manage.py collectstatic --no-input && python manage.py runserver 0.0.0.0:8000"'
@dguaraglia
Copy link
Author

Ah, forgot to add the command to run it:

UID=$UID GID=$GID docker-compose up

The reason I'm specifying the UID and GID is so that the containerized processes don't end up littering the directory with files created by root which then become a pain to clean up.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment