Docker Compose

Web applications have non-code dependencies. Things like databases and queues. Docker Compose lets you specify those dependencies.

# docker-compose.yml
version: "3"
services:
  app:
    build: ./foo
    ports:
      - 8000:5000
    environment:
      - DEBUG=True
    volumes:
      - ./foo:/app
    command: flask run --host=0.0.0.0 --port=5000
  
  db:
    image: postgres

The example will run two containers, one named app and one named db.

A db container running the standard postgres image from docker hub to provide a database to our app container on postgres://db.

The app container will run an image based on ./foo/Dockerfile. It will run flask run --host=0.0.0.0 --port=5000 instead of the CMD line. Folder foo is availble inside the container as /app. Environment variables will be set. And port 8000 of localhost will map to port 5000 inside the container.