Docker Container Cannot Access Another Container with FQDNs

I have set up two containers on an Ubuntu 20.4 server with NGINX as follows:

Both containers are accessible from the outside world and even I can access third-party APIs in the container. However, when I am trying to access container 1 from container 2 using its fully qualified domain, it times out.

I installed curl inside the container it seems that it cannot reach out to the host’s public IP address. What would be an appropriate solution? You may wonder why I am doing this because eventually these 2 services will be hosted on completely independent servers.

BTW, I posted this question on StackOverFlow and I couldn’t put all images because I am a new user.

If the fqdn is resolveable by the resolver on your host, and you did not override the containes dns resolvers yourself, it should work as is.

You can troubleshoot network issues with https://github.com/nicolaka/netshoot

Example:

* `$ docker run -it --net container:<container_name> nicolaka/netshoot`

If you replace <container_name> with the id or container name of container 2 in above example, you should get an interactive terminal in the netshoot container, that hooks into the network namespace of container 2 (=uses network interface of container 2). You can use it for further diagnostics.

1 Like

I have a same problem. Have you found a solution? @amirhb

I know that network_mode:host works, but this is not possible while having a custom bridge network. So whats the way to go?

Even replacing /etc/resolv.conf with the host on doesnt change anything. Neither does --dns.
I am lost.

1 Like

If any has a feedback about that i would appreciate. I’m stuck with that issue for days now

I created a Bridge Network in Docker and ran both containers on the same network bridge.

docker network create my_bridge_network
docker run --network=my_bridge_network …