URL of docker container that was started from inside a docker container?

I have a build machine that has several CI Build Runners running via docker-compose .

These runners build and test my server. In order to test my server, I have to run another docker-compose to start up a database and a few other mock servers (so it’s docker-compose inside of docker-compose). When I run the test servers locally, I can access them via localhost:3306 and localhost:4000 , but that doesn’t seem to work when running everything from docker inside of docker. The containers appear to be starting correctly though, but are just not accessible via localhost

What is the proper url that I should be calling to access those docker-compose servers from inside my docker container?

by their name :slight_smile:

if you have:

version: '2'

you can from your webserver, ping/access the database via its name: db

I need to ping them from outside the webserver. I’m running my tests inside my CI, which is running in a separate docker container. From that docker container I need to be able to call into the services that I start with docker-compose to run my tests.

Everything within Docker should be able to use container names as DNS records for other containers (I think).
So if you have a container called “runner” then any other container should be able to access the container called “runner” using the DNS address “runner”.

In terpz example above, his webserver accesses the database using db:1433.

Hi again.

Then you need to access it via your CI containers gateway ip.

docker inspect CI_CONTAINER | grep -i gateway

Then you can, from the CI container, use “gatewayIP:3306”

This is helpful. So I have 12 CI containers running on a single machine. Is there a way, while I’m inside of the container, to get its current gateway ip?

Really depends on the image, but you can try:

ip route list | awk ' /^default/ {print $3}'

But if you create a network manually, and add your CI containers to that, it should always have the same gateway IP, for all containers.

Another solution could also be, just to use your hosts IP address directly