How to start selenium hub and one connected node via docker-compose instead of using dockers?

I can run the image of the selenium node through:

docker run --rm=true -P -p 4444:4444 --name selenium-hub selenium/hub 

and add firefox worker via:

 docker run --rm=true --link selenium-hub:hub selenium/node-firefox 

Going to http: // localhost: 4444 / grid / console will then show the grid simply.

I do not want to use docker every time, but I have the same setup through docker-compose .

Therefore, I thought I could just do this in my docker-compose.yml :

 selenium_hub: image: selenium/hub ports: ["4444:4444"] links: - selenium_firefox_worker selenium_firefox_worker: image: selenium/node-firefox 

However, after running docker-compose up I get a message:

 selenium_firefox_node_1 | Not linked with a running Hub container selenium_firefox_node_1 exited with code 1 

and therefore the grid does not display node.

I thought I could make the link in the wrong order, but even:

 selenium_hub: image: selenium/hub ports: ["4444:4444"] selenium_firefox_node: image: selenium/node-firefox links: - selenium_hub 

gives the same error.

What am I doing wrong?

+5
source share
3 answers
 selenium_hub: image: selenium/hub ports: ["4444:4444"] selenium_firefox_node: image: selenium/node-firefox links: - "selenium_hub:hub" 

While k0pernikus answer works, I just wanted to clarify why it failed.

Node containers expect a connection to a hub, which is easily resolvable:

 hub 

not in their example, where it will be resolved as:

 selenium_hub 
+3
source

As a side note, if you are using version 2 format for docker, you need to specify a couple of env variables, otherwise node will not connect to the hub:

 version: '2' services: hub: image: selenium/hub ports: - "4444:4444" firefox: image: selenium/node-firefox environment: HUB_PORT_4444_TCP_ADDR: hub HUB_PORT_4444_TCP_PORT: 4444 links: - hub 

Credits: Containers not affiliated with docker-compose version 2

+6
source

Having stumbled upon this tutorial , this syntax appeared. And while this seems like one of my approaches, it worked.

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

Something seems to be about names, but I'm not sure.

+5
source

Source: https://habr.com/ru/post/1246572/


All Articles