Last active
November 20, 2022 21:44
-
-
Save jefftriplett/8ec40a937654f90a65d6886140215ec2 to your computer and use it in GitHub Desktop.
How I use Docker and 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
.* | |
!.coveragerc | |
!.env | |
!.pylintrc |
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
DEBUG=true | |
DATABASE_URL=postgres://postgres@postgres/postgres | |
SECRET_KEY=HAVE-IT-YOUR-WAY | |
DJANGO_ADMIN_URL=/admin/ |
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' | |
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: |
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
#!/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 \ | |
# "$@" |
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
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"] |
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
Django | |
django-environ | |
whitenoise | |
# Postgres | |
psycopg2 | |
# Redis | |
django-redis | |
redis | |
# for production | |
gunicorn | |
# for testing | |
pytest | |
pytest-django | |
pytest-sugar |
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.
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
IMO, Dockerignore should always ignore everything (*), only include what is needed for your image/container. This allows others to set up envs using whatever they want, venv or .venv. People use different naming conventions, docker ignore and should only reference files that are in VCS. If everything is being ignored that doesn't need to be included, you can remove line 13 in Dockerfile and replace it with line 20, as everything will be copied to /src including requirements. Can also add all ENV vars into a 1 liner. This is a good practice.