How do I link and scale multiple docker containers?
Asked Answered
A

2

1

I would like to use Selenium Grid's Docker images to execute tests in parallel.

In order to do so, I wish to dispatch each test suite to a different browser node. Each node would have to be paired up with its own dockerized server so that the tests may run. So my question is what is the best way to link the container pairs?

Is there a way to easily scale the server-node pairs, perhaps with Docker Compose?

I am pretty new to all of this, so apologies if what I am trying to achieve isn't very clear.

Annihilation answered 7/6, 2016 at 17:22 Comment(0)
O
1

I'm not 100% clear on the need to dispatch each test suite to a different node but it sounds like something like this should meet your requirements:

hub:
  image: selenium/hub:2.53.0
  ports:
    - "4444:4444"
firefox:
  image: selenium/node-chrome:2.53.0
  links:
    - hub
chrome:
  image: selenium/node-chrome:2.53.0
  links:
    - hub

If you save this in a directory as docker-compose.yml and then cd into the directory you can do something like:

docker-compose up -d
docker-compose scale firefox=3 chrome=3

This will give you 3 nodes with each browser and the selenium hub will handle assigning your tests to the nodes such that they are only running a single set of tests at once.

You then tell all of your tests to use a remote webdriver & you are able to control which browser gets used for each set of tests:

from selenium import webdriver
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities

driver = webdriver.Remote(
   command_executor='http://127.0.0.1:4444/wd/hub',
   desired_capabilities=DesiredCapabilities.CHROME)
driver.get("http://www.seleniumhq.org/")

Obviously you would need to modify this to use your desired language to write the tests in. I just posted a quick example in python to get you going as you didn't specify a language & that is what I am most familiar with.

EDIT: Possible way of meeting your actual requirement:

hub:
  image: selenium/hub:2.53.0
  links: 
    - app
firefox:
  image: selenium/node-chrome:2.53.0
  links:
    - hub
chrome:
  image: selenium/node-chrome:2.53.0
  links:
    - hub
test:
  image: your/testimage
  links:
    - hub
app:
  image: your/appimage

You could then start multiple instances of the whole setup by running (in the directory where the docker-compose.yml is):

docker-compose --project-name <identifier> up -d

If you change <identifier> to something unique for each instance then you can have multiple instances running at one time. You would also probably want to add a volume to your test container so that you can persist results/logs/screenshots but I don't really know enough about the setup to tell you how to do that.

I would question whether you need the selenium-hub in this case but it does add some convenience so you may still wish to use it.

Ortega answered 12/6, 2016 at 10:15 Comment(2)
Thanks for the response! However, I want to use Docker Compose to create a scalable, disposable environment. Each instance will consist of more than two containers, so rather than scaling the nodes individually, I was hoping there was a way to bring up multiple instances of the entire infrastructure.Annihilation
I made an edit which hopefully explains how you could use docker-compose to achieve that. Not sure if you've already solved your issue but if not then I hope it helps.Ortega
A
0
docker-compose up --scale firefox=3 -d

docker-compose up --scale chrome=3 -d

try this it will definitely work

Azrael answered 28/6, 2021 at 2:38 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.