Docker Compose to create multiple docker containers

Tutorial 30 – Docker Compose to create multiple docker containers

So far we have learnt how to create standalone selenium containers. The standalone container had both -> selenium grid​​ (hub) and node.​​ 

We will now learn how to spin up​​ multiple​​ docker containers using docker compose and use it to start a grid.

Scroll down the official docker-selenium page​​ https://github.com/SeleniumHQ/docker-selenium​​ 

You would see the docker compose section

The yaml (yet​​ another​​ markup​​ language) file that you see above is a docker compose file. Using this file, we can create one or multiple docker containers.

Let us open the docker-compose-v3.yml

Notice that this file has 4 sections. The first 3 sections will help us in creating chrome/edge/firefox nodes (notice the respective images), the last section would create the hub container.​​ 


Also notice above that the 3 browsers ‘depends_on’ selenium-hub, which is quite understandable.​​ 

Create a new text file at any location and open the file in notepad or any other editor

​​ 

Copy the .yml file contents from​​ https://github.com/SeleniumHQ/docker-selenium/blob/trunk/docker-compose-v3.yml​​ 

Paste it in text file


Make sure that the contents of .yml are properly pasted in the above file otherwise you would get error later.

File > Save As (make sure​​ the file name has .yml extension as shown below)

Notice below the file formatting changes and you can differentiate the different sections very clearly​​ 


Let us now start docker engine on windows by simply double clicking the docker desktop icon

Wait for the docker engine to start, you would see the docker dashboard icon once docker engine is ready

Click this docker dashboard icon, right now as you can see, no containers are running

Next cd to location where your .yml file is kept

Execute​​ docker-compose up​​ command. You will get below error because the filename that we have given is not supported. The error is suggesting us few filenames​​ 

Close the .yml file and rename the file to docker-compose.yml

​​ 

Re-execute​​ docker-compose up​​ command. This time there shouldn’t be any error.​​ 

Notice below that the respective images are pulled from docker hub and the multiple containers are created

Launch​​ http://localhost:4444​​ 

Notice below that the selenium hub is up and running. Moreover, 3 docker containers have been created. One container has firefox browser running, another container has edge, another has chrome)

Before we bring down the containers, Ctrl+C​​ 

To bring down the containers, execute​​ docker-compose down

Notice below that the containers are no more running​​ 

To run containers in background, execute​​ docker-compose up -d ​​​​ 

Refresh the session after sometime

The below command shows the 4 containers running

So this is how we can use​​ docker compose to spin up multiple docker container sessions.

Before we wrap up, let us bring down the containers

Thank you for reading!

Share On

Share on facebook
Share on twitter
Share on linkedin
Share on whatsapp
Share on tumblr
Share on email

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top

Lifetime Membership Club

LIFETIME MEMBERSHIP BIG SALE - ALL LIVE COURES JUST - 7000 RS/ 99 USD
Attend All Live courses in just 7000 rs / $99 - offer ends 10th Nov 2024