I think that's how it supposed to work. You ideally want contains to have isolation until you say otherwise.
A quick solution, on your selenium scripts, instead of localhost
specify your <machine name>
. That way, your scripts in zalenium will look to resolve the address through the network (which is still you) instead of trying to internally resolve localhost on their own network ring.
While this will probably work for you machine, it's a little bit static. You'll probably want to script it as part of your solution so it connects to multiple.
In java you can use this to get the running machine name:
InetAddress addr;
addr = InetAddress.getLocalHost();
hostname = addr.getHostName();
Alternatively, to make a more portable solution, you might want to review the docker networking pages.
I think this tutorial might help you. "Networking with standalone containers" sounds about right.
Long and short of it is when you run your docker containers you need to attach them to the same network. The default is:
--network bridge
Or create your own bridge:
docker network create --driver bridge MyBridgeName
and run both your containers on that bridge name:
docker run -dit --name MyImageName --network MyBridgeName ImageToRun
docker run -dit --name OtherName --network MyBridgeName OtherImageToRun