Can’t send request during build time in next.js with docker?

I’m trying to send a request in my getStaticProps function to my backend api from another docker container. but even though the api url is written correctly, the static page still is not created. because for the static page to be built the backend should be up already, and because it is build-time the other container is not up yet and waits for the build to be finished and the build can not be finished without the backend.

So what’s the solution to this approach? I tried setting the depends_on value to my other container, still doesn’t work. what solution would you suggest?

Source: Docker Questions