The below files can be used as a reference on how to deploy Django application in a container.
Dockerfile
This file contains hidden or 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.12.8-alpine | |
| ENV PYTHONDONTWRITEBYTECODE=1 | |
| ENV PYTHONUNBUFFERED=1 | |
| WORKDIR /app | |
| COPY requirements.txt ./ | |
| RUN pip install -r requirements.txt –no-cache-dir | |
| COPY ./myresumebuilder/manage.py ./ | |
| COPY ./myresumebuilder/myresumebuildersite ./myresumebuildersite | |
| COPY ./myresumebuilder/resumebuilder ./resumebuilder | |
| RUN adduser -D myuser | |
| USER myuser | |
| # Collect static files (if any) | |
| # RUN python myresumebuilder/manage.py collectstatic | |
| EXPOSE 8000 | |
| # For production | |
| CMD ["gunicorn", "–bind=0.0.0.0:8000", "myresumebuildersite.wsgi"] | |
| # For development | |
| # CMD ["python", "myresumebuilder/manage.py", "runserver", "0.0.0.0:8000"] |
docker-compose.yaml
This file contains hidden or 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
| # https://github.com/docker/awesome-compose/tree/master/official-documentation-samples/django/ | |
| # https://github.com/docker/awesome-compose/blob/master/django/app/Dockerfile | |
| services: | |
| db: | |
| image: postgres:17.2-alpine | |
| volumes: | |
| – ./docker-volume/data/db:/var/lib/postgresql/data | |
| env_file: | |
| – .env | |
| healthcheck: | |
| test: ["CMD-SHELL", "pg_isready -d $${POSTGRES_DB} -U $${POSTGRES_USER}"] | |
| interval: 1s | |
| timeout: 5s | |
| retries: 10 | |
| web: | |
| build: . | |
| ports: | |
| – "8000:8000" | |
| env_file: | |
| – .env | |
| depends_on: | |
| – db |
Leave a comment