During build time an application could not reach a database or api from another container.
I am migrating my projects from an older docker server to fresh dokploy server.
When i am deploying during the build time i am getting the error
This is a nextjs app trying to connect to my database. It works if i expose the port to the internet but i really don't want to do that.
On my other server i solved this problem passing the --network parameter to the build docker command so during the build time my apps could communicate with other containers on the same network without any problems.
I am also migrating another project that has a separate API/DB and an nextjs app and during the build of the nextjs app it cannot reachs the api:
What could be a possible solution in these cases?
Thank you
36 Replies
I found this while researching to some workaround: https://github.com/officialCaesardev/next-js-ssr-issue/tree/main this is the exact same thing that i am getting.
GitHub
GitHub - officialCaesardev/next-js-ssr-issue
Contribute to officialCaesardev/next-js-ssr-issue development by creating an account on GitHub.
I have read in docker forums that’s a docker issue
Hmmm. Yes. But i was able to handle it on my server (using docker without any panel). I am passing to the build the network parameter and it works fine there.
This is part of my build on my old server:
And it works but i really want to migrate all my projects to dokploy
Why do you need a network?
That was the only way i found to make it to work.
My old projects are using server actions. the functions are only querying the database over prisma.
While researching since yesterday i saw a guy that said "set the other container to host" so it will work during the build time but i didn't tried that.
I'm getting this error when deploying the repo you've shared
can you change the network to dokploy-network?

oh sorry this is not my repo. i just found tthat while researching
do you want me to download, edit and share it with you?
I was also looking for a solution to this problem and if it works and is implemented in Dokploy, then it will solve the problem many people face.
I will test later, we have a example in this repo which works fine, database + migration + nextjs app https://github.com/Dokploy/examples/tree/main/t3
GitHub
examples/t3 at main · Dokploy/examples
Examples to deploy on Dokploy. Contribute to Dokploy/examples development by creating an account on GitHub.
Hey @iraunit
Thanks for sharing your experience too. Yeah, i really don't like the idea of exposing it to the internet. This problem also happened to me when i was using the easypanel. Would be great if @Siumauricio can manage it for us.
As i said before, I solved it (on my dedicated server without any panel) by passing the --network parameter to the build. I can't remember well but i don't think i was able to use --network on buildx and only on build (i think it was a due to limitation of docker) and i had to use the env DOCKER_BUILDKIT to 0 as well.
I liked so much dokploy and i really want to keep it because it's too much work for me to manage docker in my server. I want to focus on development of my projects.
I have a trpc based project that worked fine on dokploy too. The problem is the server actions like you have a page.tsx that calls a server action function in /actions/categories.ts that has a function like getAllCategories() that simply executes prisma query (where the database is on another container) or a fetch() to an API that is on another container. So on the build log you will get "failed to lookup address information: Name or service not known"
probably have to make some small changes in the code to make it work and adapt well to dokploy, I'll try with the repository you sent me tonight probably.
thank you so much!
Hey @Siumauricio did you get any time to get a look into it? thanks
I uploaded a simple backend and frontend for you to test:
GitHub
GitHub - calliduslabs/backend
Contribute to calliduslabs/backend development by creating an account on GitHub.
GitHub
GitHub - calliduslabs/frontend
Contribute to calliduslabs/frontend development by creating an account on GitHub.
Hey, Thanks I will test now, I'm in my house rn

Np
I firstly created the backend (no dockerfile/compose) just with nixpacks
then its listening on the localhost:8080
then i created the frontend but before deploy i added the env

that points to the backend container.
ok let me test it
and this is the error

all projects that's using SSR will not work instead you expose the backend to the internet.
my solution was to add --network to docker build in my server without exposing anything.
`
it works when using the domain BACKEND_URL="http://tersting-backend-bug-f04faf-5c882d-5-161-121-59.traefik.me"
any reason why?
probably something happen inside of nextjs
using the hostname of the container it doesn't work
why don't use the domain?
got it. at least i have a way for my two old projects to be deployed in dokploy 🙂
yeah i think it's the best way. didn't think about that.
this way i don't need to expose anything to internet
There are things that work a bit differently outside of vercel, I remember a sponsor asked me for help about a redirect that in vercel worked fine but in dokploy that redirect didn't work and I noticed that the URL() object works in a different way outside of vercel, which is strange.
that's true. but in any case docker should take it easy
and like i said that won't happen in any project that i use trpc. everything will work fine. it's a SSR problem inside docker environment
Correct
Even I also have these errors in production with the docker image from dokploy, I have some redis errors but it still works.
I would like to see what other cases the networks would work, because so far it's the first time I've seen that someone really needs that
However there are solutions
Yeah at least this. @iraunit also got this problem. but he ended exposing the backend
But thanks man for your time and this amazing project. I am really enjoying dokploy!
Don't worry, if you really want that functionality you can create an Issue with a proposal and if you like a PR, I would like to help you but I am busy with other things
Np. By the way, i am migrating my projects from my server to a temporary server. After that i will erase my main server and install dokploy on it. Is there any way to "join" my temp server and then assume the manager. Later i will destroy my temporary server.
Last question for the problem we discussed: is there any way generate a traefik domain to a database container?
Not for now
what about this one?
Hmm I think you need to run the custom installation
There probably isn’t a solution for this yet, right?
I’d need to expose the database, and I’m not really comfortable with that
Actually, I don’t think I can even expose Postgres??