LinuxCommandLibrary

compose

Define and run multi-container Docker applications

TLDR

Compose action can be used to compose any existing file or new on default mailcap edit tool

$ compose [filename]
copy

With run-mailcap
$ run-mailcap --action=compose [filename]
copy

SYNOPSIS

docker compose [OPTIONS] [COMMAND] [ARGS...]

Common Commands:
docker compose up [OPTIONS]: Creates and starts containers, networks, and volumes.
docker compose down [OPTIONS]: Stops and removes containers, networks, and volumes.
docker compose ps: Lists containers and their status.
docker compose build: Builds or rebuilds service images.
docker compose logs [OPTIONS]: Displays log output from services.
docker compose exec [OPTIONS] SERVICE COMMAND [ARGS...]: Executes a command in a running container.

PARAMETERS

--file <file>, -f <file>
    Specify an alternate compose file (default: docker-compose.yml).

--project-name <name>, -p <name>
    Specify an alternate project name (default: directory name).

--env-file <file>
    Specify an alternate environment file to load.

--verbose
    Show more output, including debugging information.

--version
    Show the Compose version number and exit.

--help
    Show a help message and exit.

DESCRIPTION

compose (more commonly known as docker compose) is a powerful tool for defining and running multi-container Docker applications. It allows you to configure your application's services using a YAML file, typically named docker-compose.yml. With a single command, you can then spin up, scale, or tear down all the services defined in your configuration.

It simplifies the orchestration of complex applications by abstracting away the underlying Docker commands for each service. This makes development, testing, and staging environments much easier to manage, ensuring that your application's dependencies (databases, web servers, queues, etc.) are consistently configured and interconnected.

Originally a separate Python-based utility (docker-compose), its functionality has been integrated directly into the Docker CLI as of Docker Engine v1.13 and later, accessible via docker compose. This integration streamlines the workflow and leverages the native Go implementation of Docker, offering improved performance and maintainability.

CAVEATS

Requires a working Docker Engine installation.
Configuration is done via YAML files, which are highly sensitive to indentation and syntax.
Networking between services is handled automatically by Compose, but understanding Docker networking can be beneficial for advanced configurations.
While docker compose is the modern integrated version, older systems might still use the standalone docker-compose binary. Be aware of which version you are using.

<B>KEY CONCEPTS: DOCKER-COMPOSE.YML</B>

The heart of any Compose application is the docker-compose.yml file. This YAML file declaratively defines your application's services, networks, and volumes. Each service typically corresponds to a container and can specify its Docker image, build context, ports, environment variables, dependencies, and more. This declarative approach ensures consistent environment setup and simplifies application deployment across different machines.

HISTORY

The concept of defining multi-container applications originated with Fig, a Python-based tool acquired by Docker. This tool was then rebranded and evolved into docker-compose, initially released as a standalone utility written in Python. It quickly became an essential part of the Docker ecosystem for local development and testing.

Over time, Docker Inc. decided to integrate core Compose functionality directly into the main Docker CLI. This led to the development of docker compose (note the space, indicating a subcommand of docker), which is a Go-based implementation. This integrated version began appearing in Docker Engine 1.13 and has since become the recommended way to use Compose, offering better performance, stability, and a unified command-line experience with other Docker commands. The standalone docker-compose binary is still available for backward compatibility but is largely considered legacy.

SEE ALSO

docker(1): The core Docker CLI command for managing containers, images, volumes, etc., dockerfile(5): Manual page describing the syntax for Dockerfiles, used for building Docker images., docker-compose(1): The manual page for the standalone, legacy docker-compose command.

Copied to clipboard