Docker Selenium Hub with multiple PhantomJS Selenium Nodes on CentOS

Docker installation on CentOS is documented nicely here:

https://docs.docker.com/engine/installation/linux/centos/

Quick summary:

yum install -y yum-utils
yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
yum makecache fast
yum install docker-ce
yum list | grep docker
systemctl start docker
docker run hello-world

Find the docker you want :

https://hub.docker.com/r/selenium/

I got selenium-hub and rocketboy phantomjs (that’s the only phantomjs that worked for me from the site above):

docker pull selenium/hub
docker pull rocketboy/node-phantomjs

List all installed images:

docker images

This site proved useful for the following step:

http://www.assertselenium.com/continuous-delivery/setting-up-selenium-grid-using-docker/

Set up the dockers and start them using commands below:
Set up the selenium hub:

docker run -d -p 5000:4444 --name selenium-hub -P selenium/hub

Now set up separate dockers for phantomjs and link them back to the hub (so that the hub will distribute among these nodes)

docker run -d --link selenium-hub:hub -P --name rocketboy_phantomjs_001 rocketboy/node-phantomjs
docker run -d --link selenium-hub:hub -P --name rocketboy_phantomjs_002 rocketboy/node-phantomjs
docker run -d --link selenium-hub:hub -P --name rocketboy_phantomjs_003 rocketboy/node-phantomjs
docker run -d --link selenium-hub:hub -P --name rocketboy_phantomjs_004 rocketboy/node-phantomjs
docker run -d --link selenium-hub:hub -P --name rocketboy_phantomjs_005 rocketboy/node-phantomjs
docker run -d --link selenium-hub:hub -P --name rocketboy_phantomjs_006 rocketboy/node-phantomjs
docker run -d --link selenium-hub:hub -P --name rocketboy_phantomjs_007 rocketboy/node-phantomjs
docker run -d --link selenium-hub:hub -P --name rocketboy_phantomjs_008 rocketboy/node-phantomjs

Type “docker ps” to see your active dockers listed. “docker ps -a” will list started and stopped dockers:

docker ps
fake16814a7b        rocketboy/node-phantomjs   "/opt/bin/entry_po..."   4 weeks ago         Up 11 days                                   rocketboy_phantomjs_008
fake1674c768        rocketboy/node-phantomjs   "/opt/bin/entry_po..."   4 weeks ago         Up 11 days                                   rocketboy_phantomjs_007
fake105bb95b        rocketboy/node-phantomjs   "/opt/bin/entry_po..."   4 weeks ago         Up 11 days                                   rocketboy_phantomjs_006
fake114d33cb        rocketboy/node-phantomjs   "/opt/bin/entry_po..."   5 weeks ago         Up 11 days                                   rocketboy_phantomjs_005
fake146fbfba        rocketboy/node-phantomjs   "/opt/bin/entry_po..."   5 weeks ago         Up 11 days                                   rocketboy_phantomjs_004
fake1f3a9a3d        rocketboy/node-phantomjs   "/opt/bin/entry_po..."   5 weeks ago         Up 11 days                                   rocketboy_phantomjs_003
fake12d3acc7        rocketboy/node-phantomjs   "/opt/bin/entry_po..."   5 weeks ago         Up 11 days                                   rocketboy_phantomjs_002
fake13d6e0d8        rocketboy/node-phantomjs   "/opt/bin/entry_po..."   5 weeks ago         Up 11 days                                   rocketboy_phantomjs_001
fake10f534d2        selenium/hub               "/opt/bin/entry_po..."   7 weeks ago         Up 11 days          0.0.0.0:5000->4444/tcp   selenium-hub

You can pull up this URL (replace example_test_box.zcom with your test server URL) and see your grid console in a browser:

http://example_test_box.zcom:5000/grid/console

Now when setting the Selenium driver (Python), use something like below (replace example_test_box.zcom with your test server URL):

self.driver = webdriver.Remote("http://example_test_box.zcom:5000/wd/hub", webdriver.DesiredCapabilities.PHANTOMJS)

Now when running the tests, they will be distributed amongst the eight phantomjs dockers. Eight actually might be an overkill and slow down your test machine. In that case just stop one or two and see how much load is optimal.

Stop docker like this:

docker stop fake16814a7b

Start docker like this:

docker start fake16814a7b

To see the dynamic logs for a docker, use:

docker logs -f fake16814a7b

Enjoy!

Have not tried docker compose yet, but when I do I will post my findings.