In this post, I will be taking you through end to end steps to set up Docker-Compose on Linux machine.
To visit more such posts, follow: #TestEnvironment
Docker-Compose is a tool to define & run multiple containers in one go. It uses a configuration file in YAML format. This file defines details like image, volume, network, port etc. for each app container which is to be run. Using this file, docker-compose can bring multiple containers up in one go for one app at a time.
Docker-compose can be used in case you want to bring up several applications together each of them in a separate isolated environment. These applications can interact with each other through exposed ports and can form a complete stack solution.
For example, a complete performance testing solution stack includes a performance test tool (preferably in a distributed environment), influxDB & Grafana.
Another example is setting up an environment for the selenium grid with multiple containers with different node types.
Installing these by docker makes life easy but gets harder as we need to bring up more containers one by one. With Docker-Compose, we can bring all these apps up in one go. They run in their own container & communicate using an exposed port.
Let's setup docker-compose. This post assumes that you have a Linux instance set and also a docker installed. If that's not the case, visit post under the previous milestone step.
PREVIOUS MILESTONE STEPS
Step 00 - Set up Docker On Linux
Step 1 - Download the Docker Compose binary Step 2 - Apply executable permissions to the binary Step 3 - Test the installation Step 4 - Create example selenium docker-compose.yml file & Validate Step 5 - Run containers using docker-compose Step 6 - View containers using docker
Step 7 - Stop containers using docker-compose
Step 8 - Scale-up using docker-compose
Run below command to give executable permissions:
Use below command to verify:
On your local machine, create a file named docker-compose.yml( we will SCP this file to Linux machine. In case you wish, you can directly create this file on Linux machine using vim editor.)
Copy the below content to your file. This contains a description of 2 services which you want to bring up.
On Linux instance, create directory
Go to the above directory and give touch command to create docker-compose.yml
Open vim editor to copy this content taken from selenium official GitHub repository(and further modified to make it simple). You can also create this file locally and do WinSCP.
Give below command to validate the contents of the docker-compose file. If there is no syntax issue, it would give the content of the file as output.
Give below command to get all containers up in one go. It will pull all the images and run containers
Run below command to see running containers:
Run below command to see all containers:
docker ps -a
Go to the location where docker-compose is available.
Stop all the containers in one go
In case you wish to run multiple containers of particular service, give the command
docker-compose up -d --scale <servicename>=numberofcontainers
Congratulations you have achieved your first milestone to run a container using docker-compose!