Next.js Discord

Discord Forum

Nextjs client does not find back-end container in docker

Unanswered
Transvaal lion posted this in #help-forum
Open in Discord
Transvaal lionOP
Hi everyone, I'm trying to run my next.js app and my .NET services, but they are not communicating very well. The client side does not find the API, I'm making a fetch('https://container-name:5001/endpoint') but this returns me an net::ERR_NAME_NOT_RESOLVED error in the console, I've tried calling on the localhost, but I don't really know what to do and I just started using docker, any help would be appreciated thank you!

3 Replies

Could you share your docker compose file?

You should be referencing the service name not the container name
But you need to make sure both apps are running on the same docker compose so they can communicate through the service name as the host name.
Calling them by localhost won’t work because that references your local machine, “localhost” would only work if your backend was the one running on the container and needs to be accessed externally by your web app that’s running locally, makes sense? I’m fairly new to docker too but I had big time figuring this stuff out myself lol