【Docker】Docker Compose

Posted by 西维蜀黍 on 2020-05-24, Last Modified on 2021-10-27

Install

Run this command to download the current stable release of Docker Compose:

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

Apply executable permissions to the binary:

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

Set a soft link

$ sudo ln -s /usr/local/bin/docker-compose /usr/bin/docker-compose

Test the installation.

$ docker-compose --version

Usage

# List all running containers:
$ docker-compose ps

# Create and start all containers in the background using a docker-compose.yml file from the current directory:
$ docker-compose up -d

# Stop all running containers:
$ docker-compose stop



# Start all containers, rebuild if necessary:
$ docker-compose up --build

# Start all containers using an alternate compose file:
$ docker-compose --file path/to/file up

# Stop and remove all containers, networks, images, and volumes:
$ docker-compose down --rmi all --volumes

# Follow logs for all containers:
$ docker-compose logs --follow

# Follow logs for a specific container:
$ docker-compose logs --follow container_name

Reference