'How to run wdio tests with existing container in selenoid webdriverio

Current Situation:

I have 32 core machine and maximum I set 50 threads. I've two jobs which has 50 tests each so i distribute jobs with limit 25 in each jobs as shown below.

Concern

If we set the limitation per job and let's say if have 3 jobs, it will set 75 threads which is more than the selenoid recommended (core * (1.5 ~ 2)).

 services: [
        ['selenoid-standalone', {
            pathToBrowsersConfig: 'browsers.json',
            customSelenoidContainerName: 'selenoid',
            dockerArgs: ['--rm'],
            selenoidArgs: ['-limit', '25', '-timeout', '3m'],
        }]
    ],

Problem:

Currently i am finding a solution to run the test with existing container. When i tried, I got the below error.

SevereServiceError: 
A service failed in the 'onPrepare' hook
SevereServiceError: Unable to start selenoid container 
Error: Command failed with exit code 125: docker run -d --name wdio_selenoid -p 4444:4444 -v /var/run/docker.sock:/var/run/docker.sock -v <pathToAutomationFolder>/:/etc/selenoid/:ro --rm aerokube/selenoid:latest-release -limit 50 -timeout 3m
docker: Error response from daemon: driver failed programming external connectivity on endpoint wdio_selenoid (c1f930197a24c85cd9318933586e108eb4b52fee522622209f9566e80943ee1f): Bind for 0.0.0.0:4444 failed: port is already allocated.
f296c41ecc736be072872adaa7316d1fbe68636e1e7f44ca0b3a255a37c74826


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source