Docker compose is the way to handle a multi container application.

File: "docker-compose.yml"

services:
  django-app:
    build:
      context: .
      dockerfile: Dockerfile
    # TODO switch this command out with UNICORN
    command: python manage.py runserver 0.0.0.0:8000
    volumes:
      - .:/app
    expose:
      - "8000" # Exposes port 8000 to the internal Docker network
    env_file:
      - document_classification/document_classification_project/.env

  nginx:
    image: nginx:latest
    volumes:
      - ./nginx/default.conf:/etc/nginx/conf.d/default.conf
    ports:
      - "80:80"
    depends_on:
      - django-app

Yes the version tag is deprecated and not needed anymore.

Docker compose

execute docker compose file:

docker compose up

this should take care of most changes in the source files, if not, add the --build tag at the end

stop all docker containers spawned via docker compose up

docker compose stop

remove all stopped docker containers that were defines via docker compose up

docker compose rm

Services

each service corresponds to a docker container. docker compose builds and starts them all together in the right order.

django-app and nginx are just names I chose to design the containers.

build

build defines the build configurations for django-app service
context: . indicates that it should use the current directory (as indicated by .) as the context. The Dockerfile needs to be an actual DockerFiles.

the command is run inside of that container. It overwrites the one inside of the Dockerfile.

Volumes

This is a way to share data between the host and the container. The host is the server where the containers are running.

I actually don't know why this is used for django-app. I should ask someone about it. It would probably work without it as well.

For nginx its to copy the settings inside of the container which is downloaded via nginx:latest.

notice that there is no dockerfile for nginx