I have an Android app that needs some micro-services to be running to be able to work correctly. So each micro-service (when started correctly) opens a specific port on localhost and listen on it. All the services are dockerized.
So currently, I have created a docker-compose files with all the necessary micro-services. A typical micro-service looks like this:
In the snippet above you can see the port mapping I use in my docker-compose file.
So anyway, what I do then is to run ‘docker login …’ and ‘docker-compose up -d’ to start the services.
The problem I’m having is that the ports that are opened by the services are opened on the host and not inside the container. So inside the container ‘localhost:4002’ is not accessible.
On the host machine, however, ‘localhost:4002’ is accessible, but I don’t have any means to connect to it from within the container. Even if I did have a way, it’s not exactly a good solution. Because I’ll have port conflicts if I try to run concurrent builds on bitrise.
So the question I’m asking here is:
Is there a possibility of making each container(build) have it’s own network separate from the host and that when I start the services in each container the ports are mapped to that container’s network and not the host machine?
Please let me know if you have any questions or anything is unclear.
…it works. the host ports are accessible to the container.
however, I don’t think I have control over how bitrise.io starts the docker-android container?
Also as i mentioned earlier, this solution, isn’t really desirable in case I need to run concurrent builds.
Just heard on the Slack channel that each build uses its own host, so I guess we should be good with this solution (or something similar). I need to have access to the ports I open from within the container.
No, I gave up on that. The workaround I ended up using is to use the default gateway address: DOCKER_HOST=$(ip route | grep default | awk '{print $3}')
And then I can check if the service has started properly: bash ./scripts/wait-for-service.sh $DOCKER_HOST:4002