Skip to main content

Example of a dockerCompose YAML

Here's an example of a Docker compose yaml file.

version: '3.9'
services:
frontend:
image: nginx
ports:
- "80:80"
depends\_on:
- backend
backend:
build:
context: ./backend
ports:
- "5000:5000"
depends\_on:
- database
database:
image: postgres
environment:
POSTGRES\_USER: myuser
POSTGRES\_PASSWORD: mypassword
POSTGRES\_DB: mydatabase

As you can see, there are three services

  1. Frontend

  2. Backend

  3. Database

The order in which it starts is based on the dependencies.

Frontend Depends on Backend

Backend Depends on Database

Hence the order: Database -> Backend -> Frontend

The three services will start and boom, that's it. The commands are in the next slide.