Docker Compose
Introduction to Compose
Compose is a tool for defining and running multi-container Docker applications. With Compose, you can use YML files to configure all the services your application requires. Then, using a single command, you can create and start all services from the YML file configuration.
If you don't understand YML file configuration yet, you can read the YAML introductory tutorial first.
Three steps to use Compose:
Use a Dockerfile to define the application's environment.
Use docker-compose.yml to define the services that make up your application so they can run together in an isolated environment.
Finally, execute the docker-compose up command to get the entire application up and running.
The configuration example of docker-compose.yml is as follows (see configuration parameters below):
Example
yaml configuration example
version: '3'
services:
web:
build: .
ports:
- "5000:5000"
volumes:
- .:/code
- logvolume01:/var/log
links:
- redis
redis:
image: redis
volumes:
logvolume01: {
}
Compose installation
On Linux, we can download its binary package from Github for use. The latest released version address: https://github.com/docker/compose/releases .
Run the following command to download the current stable version of Docker Compose:
v2.20.3 was selected for this example
$ sudo curl -L "https://github.com/docker/compose/releases/download/v2.20.3/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
The picture below indicates that the download is complete
To install a different version of Compose, replace v2.20.3. Version viewing link:
https://github.com/docker/compose/releases
Docker Compose is stored on GitHub and is not stable.
Apply executable permissions to the binary:
$ sudo chmod +x /usr/local/bin/docker-compose
Create a soft link:
$ sudo ln -s /usr/local/bin/docker-compose /usr/bin/docker-compose
Test whether the installation is successful:
[root@localhost bin]# docker-compose version
Docker Compose version v2.20.3