Selenium Grid with Docker Compose
Tags: docker, webdev, testing, tutorial
Published: 2021-07-28 12:36:18

In this tutorial, we will cover how to set up Selenium Grid with Docker Compose. We will talk about why we need Docker Compose and look into how to implement a Docker Compose file. We will also cover how to set up parallel execution with Docker Compose & Selenium Grid.

### Why use Docker Compose?
- **No need to remember Docker commands**: With Docker compose, you don't need to remember all different types of docker commands which we covered in our previous post
- **Run multiple containers together**: Docker compose allow you to run multiple containers together as a service instead of spinning up each one-by-one
- **Spin up Grid with multiple browsers using a single command**: With just one command docker-compose up you can spin up Selenium Grid with multiple browsers integrated with it

Docker Compose makes it really easy for anyone to get started with Docker, even if they are not familiar with how Docker works.

---

### Setting up Docker Compose file
To set up Selenium Grid, we will use the Docker Compose file provided in the Selenium GitHub repository  - 

![Selenium Grid Docker Compose file](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2oaghnzg1m0wbsdvlsz1.png)  

This command is equivalent to the Docker network command we used in the previous post. It will spin up a Selenium Hub on port 4444 and will have Chrome and Firefox instances set up as well.

---

### Run Docker Compose file
To run the Docker Compose file, simply run the following command on the terminal - `docker-compose up`

![Grid Console](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/gpca9653pbi8iwcayda9.png)
 
There you go, you just spun Selenium Grid with Chrome and Firefox with just one single command. That's the magic of using Docker Compose. 

---

### Setup Parallel Execution with Docker Compose
There are 2 ways to set up parallel execution for Selenium Grid using Docker Compose -
- **Updating Docker Compose file**: Add `NODE_MAX_INSTANCES` and `NODE_MAX_SESSION` to the Docker services 

![NODE_MAX_INSTANCES & NODE_MAX_SESSION](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/hu49ji4f5oed7gdvzl5w.png) 

- **Dynamically increasing the nodes**: using Docker scale command, you can also dynamically add more nodes - `docker-compose up --scale firefox=3` this will total 3 nodes for Firefox

---

### Conclusion
Docker Compose is a great way to run Selenium Grid locally. This will allow anyone in your team to spin up a grid and start running tests on any specified browser by just using a single command docker-compose up 

#### Check out the video below to learn more about how to setup Selenium Grid with Docker Compose –

{% youtube BEaGIhmKypk %}

---

📧 Subscribe to my [mailing list] (https://bit.ly/sdet-u-mailing-list) to get access to more content like this as well as free access to a Private Facebook community

👍 You can follow my content here as well - 
- [Twitter](https://twitter.com/sdetunicorns)
- [LinkedIn](https://www.linkedin.com/company/sdetunicorns)

...

I love coffees! And, if this post helped you out and you would like to support my work, you can do that by clicking on the button below and buying me a cup of coffee -

<a href="https://www.buymeacoffee.com/automationbro">![Buy me a coffee](https://dev-to-uploads.s3.amazonaws.com/i/4aw2ub3f4qkyjk0ivwt4.png)</a>

You can also support me by liking and sharing this content.

---

#### Enjoyed this read? Discover more insightful articles on software testing and development on my [blog](https://sdetunicorns.com/blog). 🌐