Notes to Self

Alex Sokolsky's Notes on Computers and Programming

Docker Compose

Docker compose offers high level of abstraction for service definition.

Installation

Seems to be installed with regular docker:

alex@latitude7490:~/ > sudo docker version
[sudo] password for alex:
Client: Docker Engine - Community
 Version:           23.0.1
 API version:       1.42
 Go version:        go1.19.5
 Git commit:        a5ee5b1
 Built:             Thu Feb  9 19:47:01 2023
 OS/Arch:           linux/amd64
 Context:           default

Server: Docker Engine - Community
 Engine:
  Version:          23.0.1
  API version:      1.42 (minimum version 1.12)
  Go version:       go1.19.5
  Git commit:       bc3805a
  Built:            Thu Feb  9 19:47:01 2023
  OS/Arch:          linux/amd64
  Experimental:     false
 containerd:
  Version:          1.6.16
  GitCommit:        31aa4358a36870b21a992d3ad2bef29e1d693bec
 runc:
  Version:          1.1.4
  GitCommit:        v1.1.4-0-g5fd4c4d
 docker-init:
  Version:          0.19.0
  GitCommit:        de40ad0
alex@latitude7490:~/ > sudo docker compose version
Docker Compose version v2.16.0

Yet:

> docker-compose
zsh: command not found: docker-compose

Check therelease page and then:

sudo curl -L "https://github.com/docker/compose/releases/download/v2.16.0/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose

Then:

sudo chmod +x /usr/local/bin/docker-compose

Finally:

> docker-compose --version
Docker Compose version v2.16.0

Reference

https://docs.docker.com/compose/reference/

Compose File Spec

https://docs.docker.com/compose/compose-file/

Example Use

sudo docker compose up -d

Summary

Command Description
docker compose up Create and start containers
docker compose up -d Create and start containers in background
docker compose up --build Rebuild images before starting containers
docker compose stop Stop services
docker compose down Stop and remove containers and networks
docker compose ps List running containers
docker compose logs View the logs of all containers
docker compose logs <service> View the logs of a specific service
docker compose logs -f View and follow the logs
docker compose pull Pull the latest images
docker compose build Build or rebuild services