Docker Compose is a tool for defining and running multi-container Docker applications. It uses a YAML file, called docker-compose.yml
, to configure the application’s services, networks, and volumes. With Compose, you can create and start all the services from the configuration with a single command.
The docker-compose.yml
file is at the heart of Docker Compose. It defines the services, their dependencies, and the configuration for each service. Here is an example of a simple docker-compose.yml
file:
version: '3'
services:
web:
build: .
ports:
- "5000:5000"
redis:
image: "redis:alpine"
In this example, the docker-compose.yml
file defines two services: web
and redis
. The web
service is built from the Dockerfile
in the current directory, and its port 5000
is mapped to the host’s port 5000
. The redis
service uses the redis:alpine
Docker image.
To start the services defined in the docker-compose.yml
file, you can run the following command:
$ docker compose up
This command creates and starts the services defined in the docker-compose.yml
file. If you want to build the images before starting the services, you can use the --build
flag:
$ docker compose up --build
If you want to automatically rebuild the services when the docker-compose.yml
file changes, you can use the --watch
flag:
$ docker compose up --watch
To stop the services, you can use the following command:
$ docker compose down
This command stops and removes the services and their networks and volumes.
For more information about Docker Compose, you can refer to the official documentation.
The GenAI Stack, introduced in this blog post, is an example of a complex Docker Compose application. It includes several services, such as Redis, PostgreSQL, FastAPI, and Grafana, that work together to provide a complete AI/ML development environment. The docker-compose.yml
file for the GenAI Stack is available in the GitHub repository.
To learn more about the GenAI Stack, you can refer to the official documentation.
Sources:
- https://docs.docker.com/compose/
- https://docs.docker.com/compose/compose-file/
- https://github.com/docker/genai-stack/blob/main/docker-compose.yml
- https://www.docker.com/blog/introducing-a-new-genai-stack
- https://docs.docker.com/engine/swarm/stack-deploy/
- https://sensu.io/resources/whitepaper/learn-sensu-go
- https://developers.redhat.com/articles/2018/12/13/creating-custom-stacks-eclipse-che
- https://grafana.com/tutorials/grafana-fundamentals
- https://buildpacks.io/docs/operator-guide/create-a-stack
- https://www.docker.com/blog/deploy-gpu-accelerated-applications-on-amazon-ecs-with-docker-compose
- https://docs.docker.com/compose/release-notes
- https://www.docker.com/blog/guest-post-calling-the-docker-cli-from-python-with-python-on-whales