Skip to content

Instantly share code, notes, and snippets.

@jefftriplett
Last active November 20, 2022 21:44
Show Gist options
  • Star 7 You must be signed in to star a gist
  • Fork 5 You must be signed in to fork a gist
  • Save jefftriplett/8ec40a937654f90a65d6886140215ec2 to your computer and use it in GitHub Desktop.
Save jefftriplett/8ec40a937654f90a65d6886140215ec2 to your computer and use it in GitHub Desktop.
How I use Docker and Compose
.*
!.coveragerc
!.env
!.pylintrc
DEBUG=true
DATABASE_URL=postgres://postgres@postgres/postgres
SECRET_KEY=HAVE-IT-YOUR-WAY
DJANGO_ADMIN_URL=/admin/
version: '2'
services:
postgres:
container_name: YOUR-PROJECT-postgres-db
restart: always
image: postgres:latest
ports:
- "5432:5432"
volumes:
- postgres_data:/var/lib/postgresql/data/
redis:
image: redis:3.0
web:
container_name: YOUR-PROJECT-web
build:
context: .
dockerfile: Dockerfile
# user: django
depends_on:
- postgres
- redis
restart: always
ports:
- "8000:8000"
env_file: .env-docker
volumes:
- .:/src
# command: /gunicorn.sh
volumes:
postgres_data:
#!/bin/bash
# apply database migrations
python manage.py migrate --noinput
# collect static files
python manage.py collectstatic --noinput
python manage.py runserver 0.0.0.0:8000
# Start Gunicorn processes
#echo Starting Gunicorn.
#exec gunicorn app.wsgi:application \
# --name app \
# --bind 0.0.0.0:80 \
# --workers 3 \
# --log-level=info \
# --log-file=/src/logs/gunicorn.log \
# --access-logfile=/src/logs/access.log \
# "$@"
FROM python:3.6.1
# This prevents Python from writing out pyc files
ENV PYTHONDONTWRITEBYTECODE 1
# This keeps Python from buffering stdin/stdout
ENV PYTHONUNBUFFERED 1
EXPOSE 8000
WORKDIR /src
COPY requirements.txt /src/requirements.txt
RUN mkdir -p /src/assets \
&& mkdir -p /src/logs \
&& chmod 755 /src \
&& pip install --no-cache-dir -r /src/requirements.txt
COPY . /src/
CMD ["/src/docker-entrypoint.sh", "-n"]
Django
django-environ
whitenoise
# Postgres
psycopg2
# Redis
django-redis
redis
# for production
gunicorn
# for testing
pytest
pytest-django
pytest-sugar
@jordan-carson
Copy link

re: you can remove line 13 in Dockerfile and replace it with line 20

This will invalidate my cache and cause a rebuild when I don't want it to.

Fair point.

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