Docker Compose Integration
The Docker CLI provides seamless integration with Docker Compose, allowing users to manage multi-container applications directly from the command line. This integration is achieved through the compose
package, which is a part of the Docker CLI.
The compose
package provides a streamlined way to interact with Compose files and commands. When you execute a Docker Compose command, such as docker compose up
, the CLI delegates the command to the compose
package. This package then interprets the command, reads the Compose file (usually named docker-compose.yml
), and executes the necessary actions to manage the containers defined within the Compose file.
Key Features
The compose
package offers a range of features for interacting with Compose files, including:
- Command Execution: Executes Docker Compose commands like
up
,down
,build
,run
, andexec
. - Compose File Handling: Parses and validates Compose files (
docker-compose.yml
). - Container Management: Creates, starts, stops, restarts, and removes containers defined in the Compose file.
- Service Management: Manages services, including building and deploying images.
- Network Management: Creates and configures networks for containers.
- Volume Management: Creates and mounts volumes for containers.
Usage
To use Docker Compose integration, you need to have a Compose file in your project directory. This file defines the services and configurations for your multi-container application.
Here’s a basic example of a Compose file:
version: "3.7"
services:
web:
image: nginx:latest
ports:
- "80:80"
db:
image: mysql:latest
To interact with your Compose file using Docker CLI, you can use the docker compose
command:
- Start the application:
docker compose up
- Stop the application:
docker compose down
- Build the services:
docker compose build
- Run a command in a service:
docker compose run web bash
Further Exploration
For detailed information on Docker Compose integration, including advanced features, troubleshooting, and API references, please refer to the following resources: