Docker Compose
Docker Compose is another best tool for docker to set up multi-container environments. Using this creates a single compose file defining all the containers with their environments. You can easily use a single command to build images and run all the containers.
There is a three-step process to work with Docker Compose.
1. Define the application environment with Dockerfile for all services.
2. Create a docker-compose.yml file defining all services under the application.
3. Run docker-compose up to run all services under applications.
You must have Docker Engine installed on your system. If you don’t have already installed it, Visit our Docker installation section of this tutorial.
Install Docker Compose
Visit the Docker compose official Github page and download the latest version of the Docker compose tool. You can also install Docker compose 1.16.1 using the following command. Before installing the specific version, You must check the compatibility on the releases page with your docker version.
Docker Compose Example File
A docker-compose.yml file is required to create to start working with the docker compose. Below is a sample configuration file of version 3. This file has only one service added to it named web.
Docker Compose CLI Reference
The docker-compose command provides a number of subcommands to manage Docker containers with docker-compose. Please find below details of the subcommands. Before reading the below commands remember that you passed service name as an argument (not container name)
build –
The build option is used to build images for services for which build is defined.
up –
Use to create docker containers with available services in docker-compose.yml file in the current directory. Use -d switch to launch containers in daemon mode.
down –
This will stop and delete all containers, network, and associated images for the services defined in a config file
ps –
This will list all containers created for the services defined in a config file with their status, port bindings, and command.
exec –
This will execute a command to the running container. For example list files in containers associated with web service.
start –
This will start stopped containers of the services defined in config file
stop –
This will stop running containers for the services defined in config file
restart –
This will restart containers of the services defined in config file
pause –
This will pause running containers for the services defined in the config file.
unpause –
This will start paused containers for the services defined in the config file.
rm –
This will remove stopped containers for the services defined in the config file.
0 Comments
CAN FEEDBACK
Emoji