Docker container doesn't resolve hostname from another docker container in same network

I have created 2 containers.

The first one is a nginx server with name angular_simple_crud_app which is running an angular project

The other one is a json-server with name fake_server, in order to produce data to the first container.

Furthermore, I have created also a bridge network called isolated_network in order to allow the containers to communicate throughout container name

I face a problem with the first container, because when i open a browser the nginx cannot resolve the container name of the json-server.

But when i exec in nginx container and execute a curl to the json-server i get the correct results.


Do you have any suggestions?

if you want to run the app, execute the file


I am confused about the post. Last time I checked angular was still rendered in the browser and only static files where served by a web server (like nginx). Thus, the host executing the angular process needs to able to reach the fake_server service, not the web server.

Thanks for the answer,
The solution that i found is to create a json file in the angular project before spin up the container and pass them the ip of the host-machine in order to use that instead the container name (fake_server).

Do you think that this solution is a good one?

Thank in advance.

In the real world usualy you end up having domain names that point to external entrypoints like loadbalancers and/or reverse proxies. Does your solution cover such a scenario?

You might want to introduce an enviornment variable to pass the domain name or ip into your ngninx container and render it in the file you serve with your angular application.

Also you might want to consider to add a reverse proxy in front of your nginx server and your other backend services, to provide a single entrypoint that dispatches the requests according subdomains or context paths to the target containers.

1 Like