Django project
Quickstart: Compose and Django
Dockerfile for virtualenv project
FROM python:latest
FROM python:3
ENV PYTHONUNBUFFERED 1
RUN mkdir /src
WORKDIR /src
COPY requirements.txt /src/
RUN pip install -r requirements.txt
COPY . /src/version: "3"
services:
web:
build: .
command: python manage.py runserver 0.0.0.0:8000
volumes:
- .:/src
ports:
- "8000:8000"Dockerfile for pipenv project with Postgres, Gunicorn Nginx
FROM python:latest
# set default environment variables
ENV PYTHONUNBUFFERED 1
ENV PYTHONDONTWRITEBYTECODE 1
# set work directory
WORKDIR /usr/application/src
# Add current directory code to working directory
COPY . .
# install environment dependencies
RUN pip install --upgrade pip
RUN pip install pipenv gunicorn
# Install project dependencies
RUN pipenv install --skip-lock --system --dev
ENTRYPOINT ["/usr/application/src/entrypoint.sh"]version: "3.8"
services:
db:
container_name: db
image: postgres:12.0-alpine
volumes:
- ./db_data:/var/lib/postgresql/data/
networks:
- backend
environment:
POSTGRES_DB: django_db
POSTGRES_USER: django_user
POSTGRES_PASSWORD: django_user
web:
container_name: web
build: .
env_file: .env
depends_on:
- db
networks:
- backend
volumes:
- static_files:/home/{user}/webroot/static
- ./mediafiles/:/home/{user}/webroot/media
command: gunicorn {project_name}.wsgi:application --bind 0.0.0.0:8000
nginx:
image: nginx:1.19.0-alpine
container_name: nginx
volumes:
- static_files:/webroot
- ./mediafiles/:/webroot
- ./config/nginx/:/etc/nginx/conf.d
networks:
- backend
ports:
# HOST_PORT:CONTAINER_PORT When HOST_PORT is defined, the service is accessible outside
- 80:80
depends_on:
- web
networks:
backend:
volumes:
static_files:
To migrate the database:
To create User:
Last updated