# Building a Docker compose file
```dockerfile=
# This is your docker compose version.
# The version of compose is set by your docker version. That can be found here.
# https://docs.docker.com/compose/compose-file/compose-versioning/
version: "3"
# All your containers are stored inside this services tag.
services:
# This is one of the containers in this example. It's name is db.
db:
# The image for docker to pull down before starting the container.
image: postgres
# This is the hostname that other containers can reach this one.
# They have to be on the same docker network for this to work.
hostname: postgresql
# Volumes are where your docker container can stores persistant information.
volumes:
# - local/directory:/container/directory
- ./data/db:/var/lib/postgresql/data
# Environment variables are predefined knobs.
# You can set before starting your container.
# They are useful for defining usernames or UIDs for the container to run as.
environment:
# PUID and PGID are unique IDs given to each user on linux.
# To creat a new user and get it's IDs use.
# useradd youruser; id youruser
- PUID=1000
- PGID=1000
- POSTGRES_DB=postgres
- POSTGRES_USER=postgres
- POSTGRES_PASSWORD=postgres
web:
build: .
command: python manage.py runserver 0.0.0.0:8000
volumes:
- .:/code
ports:
- "8000:8000"
networks:
- mynetwork
depends_on:
- db
networks:
mynetwork:
# External networks have to already exist to use them.
# They can either be from an other container or created manually using.
# docker network create mynetwork || true
external: true
```