What is Docker Compose
maindocker compose up.repository·main·Indexed 12 days ago
https://github.com/docker/composeA tool for defining and running multi-container Docker applications using a declarative Compose file format. It allows developers to manage the entire application lifecycle, including creating and starting containers, with a single command: `docker compose up`.
docker compose up.docker compose bridge transformations command is used to manage transformation images within the Docker Compose bridge environment. It allows you to create new transformations or list the ones currently available.By default, docker compose up detects changes in a service's configuration or image and recreates the container (while preserving mounted volumes). You can control this behavior using the following flags:
--force-recreate to stop and recreate all containers even if their configuration and image haven't changed.--no-recreate to prevent Compose from picking up changes and recreating existing containers.--always-recreate-deps to ensure dependent containers are also recreated (this is incompatible with --no-recreate).When running docker compose up in attached mode, you can manage which service logs are streamed to your terminal:
--attach <service> to restrict log attachment to only the specified services.--no-attach <service> to prevent logs from specific (e.g., very verbose) services from flooding your output.--attach-dependencies to automatically attach to the log output of dependent services.--no-log-prefix to suppress the service name prefix in logs and --timestamps to show timestamps.The EventProcessor interface allows you to monitor Compose operations (like up, down, or build) in real-time. It provides hooks to react to the lifecycle of a Compose operation and the individual resource changes within it.
An EventProcessor implements three main methods:
Start(ctx, operation): Triggered when a Compose operation begins.On(events...): Triggered with progress events for individual resource changes (e.g., pulling an image, starting a container).Done(operation, success): Triggered when the operation completes, providing the success/failure status.Docker Compose allows extending the service abstraction to manage resources via third-party runtimes (e.g., cloud services) using the provider attribute.
To create a valid extension, your provider binary must:
PATH or be a Docker CLI plugin.compose command with up and down subcommands.stop subcommand to support docker compose stop.metadata subcommand to describe its interface.compose up command is idempotent.Use the project-name flag to tag resources so they can be correctly released during the down lifecycle.
database:
provider:
type: awesomecloud
options:
type: mysql
size: 256
name: myAwesomeCloudDBA service managed by a provider can pass configuration to dependent services using setenv or rawsetenv messages.
Scenario:
services:
app:
image: myapp
depends_on:
- database
database:
provider:
type: awesomecloudsetenv: If the provider emits {"type": "setenv", "message": "URL=https://cloud.com/db"}, the app service receives DATABASE_URL=https://cloud.com/db (prefixed with the service name).rawsetenv: If the provider emits {"type": "rawsetenv", "message": "SECRET_KEY=xxx"}, the app service receives SECRET_KEY=xxx exactly.Warning on rawsetenv: Since there is no prefixing, keys must be unique. If a rawsetenv key collides with an existing variable (including those in the environment section), the existing value is overwritten and Compose logs a warning.
services:
app:
image: myapp
depends_on:
- database
database:
provider:
type: awesomecloudThe docker compose alpha dry-run command allows you to simulate the execution of a command. This is useful for testing your configuration and verifying what actions would be taken without actually modifying your containers, networks, or volumes.
docker compose alpha dry-run <command>Using Docker Compose follows a three-step process:
Dockerfile to ensure your application environment can be reproduced anywhere.compose.yaml file to define the services that make up your app so they can run together in an isolated environment.docker compose up to start and run your entire application.Example compose.yaml:
services:
web:
build: .
ports:
- "5000:5000"
volumes:
- .:/code
redis:
image: redisThe docker compose alpha watch command allows you to watch your build context for changes. When files in the context are updated, Docker Compose can automatically rebuild or refresh containers.
Note: This is currently an alpha feature and may be subject to change.
docker compose alpha watchBefore building Docker Compose from source, ensure you have the following dependencies installed based on your operating system:
make, and go (check go.mod for the minimum required version).make, and go (check go.mod for the minimum required version).make, and go (check go.mod for the minimum required version).Use the --rm flag to automatically remove the container once the command finishes executing. This is particularly useful for one-off tasks like database migrations. Using --rm also overrides any restart policy defined in the service configuration, ensuring the container is removed even if it was configured to restart.
$ docker compose run --rm web python manage.py db upgrade