This guide demonstrates how to define and manage your multi-container Django, Nginx, and PostgreSQL application stack using Docker Compose. Compose simplifies the process of running multi-service applications compared to managing individual docker run commands.

Prerequisites

Before starting this lab, ensure you have completed the steps in the previous guide sections to have your Django application code, Dockerfiles (for Django, Nginx, and potentially Postgres if you built a custom one), and Nginx configuration ready.


1. Install Docker Compose

Docker Compose allows you to define and run multi-container applications with a YAML file. Since Docker Engine v2.0, docker compose (without the hyphen) is often included as a Docker plugin. If you are using an older version or need the docker-compose (with hyphen) standalone binary, install it via pip.


2. Define Your docker-compose.yml

A docker-compose.yml file is a YAML file that defines your application's services, networks, and volumes. Create this file in your project root directory (where your manage.py, nginx directory, and Dockerfile are located).

(Note: The original prompt suggested build: ./myPostgres03. While possible, it's much more common to use the official image: postgres:... directly in docker-compose.yml as shown in Option 2 above. I've included both as comments for clarity, but recommend using the image approach.)

What’s here?