Docker Compose
Docker Compose is a tool that makes running multiple Docker containers much easier, than with Docker
run commands
Structured way to contain normal common Docker commands and allow you to edit
Combinations of Command Line Tools and Configurations file
(Declarative – Create file with YAML commands and Imperative way - CLI)
Docker compose to replace run commands you are using over and over. Handles multiple containers at a
time
Multiple containers as a single service
Tool for defining and running multi container docker apps
Using Yaml for configuration of compose services
You can start, stop and scale up docker compose services
Up: docker compose up (Spin up all of the services)
Stop: docker compose down (Tear it all down)
Logs: View all logs in a single stream
Install Docker Compose
curl -L "https://github.com/docker/compose/releases/download/1.24.0/docker-compose-$(uname -s)-$
(uname -m)" -o /usr/local/bin/docker-compose
chmod +x /usr/local/bin/docker-compose
docker-compose version
*************************************************************************************
Create new directory
At new directory, create new file and name of the file is docker-compose.yml or docker-compose.yaml
Add below script at docker compose file
Using vi editor for creating file
‘vi docker-compose.yaml or vi docker-compose.yml
Refer notepad
Save and exit file from vi editor
Time for Run Docker compose file
Command for validate the syntax or validity of file by command
‘docker-compose config
Get to know more about version, refer below web site
Compose and Docker compatibility matrix
https://docs.docker.com/compose/compose-file/
Run / Execute / Up : Docker Compose is
‘docker-compose up -d
‘docker ps or docker-compose ps
-d indicates – De attached mode
Down – Docker Compose is
‘docker-compose down
Want to incorporate Port number at Nginx server
- Refer notepad
Up Docker Compose
‘docker-compose up -d
‘docker ps or docker-compose ps
‘docker-compose top
(Get formatted nice output)
‘docker -compose logs
After completion, create new browser where you supply
< Public DNS Value of instances or Public ip address: Port Number>
Example: http://ec2-54-226-71-49.compute-1.amazonaws.com:8095/
Down Docker Compose
‘docker-compose down
Scale up for container services
‘docker-compose up -d –scale database = 3
‘docker ps or docker-compose ps
‘docker-compose down
Points to Remember
You can create custom docker compose file without use of docker-compose.yaml.
Example, if your file is mongodb.yaml then how to apply docker compose is
‘docker-compose -f mongodb.yaml up -d (De attached mode)
Or
docker-compose -f mongodb.yaml up (Attached mode)
Down
docker-compose -f mongodb.yaml down