D
Dokploy8mo ago
dx

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
#12 78.67 Raw query failed. Code: `unknown`. Message: `Kind: Server selection timeout: No available servers. Topology: { Type: Unknown, Servers: [ { Address: buscacep-db-a06dbf:27017, Type: Unknown, Error: Kind: I/O error: failed to lookup address information: Name or service not known, labels: {} } ] }, labels: {}`
#12 78.67 Raw query failed. Code: `unknown`. Message: `Kind: Server selection timeout: No available servers. Topology: { Type: Unknown, Servers: [ { Address: buscacep-db-a06dbf:27017, Type: Unknown, Error: Kind: I/O error: failed to lookup address information: Name or service not known, labels: {} } ] }, labels: {}`
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:
#12 40.11 errno: -3008,
#12 40.11 code: 'ENOTFOUND',
#12 40.11 syscall: 'getaddrinfo',
#12 40.11 hostname: '[redacted]-api-e413a6'
#12 40.11 }
#12 40.11 }
#12 40.11 errno: -3008,
#12 40.11 code: 'ENOTFOUND',
#12 40.11 syscall: 'getaddrinfo',
#12 40.11 hostname: '[redacted]-api-e413a6'
#12 40.11 }
#12 40.11 }
What could be a possible solution in these cases? Thank you
36 Replies
dx
dxOP8mo ago
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.
Siumauricio
Siumauricio8mo ago
I have read in docker forums that’s a docker issue
dx
dxOP8mo ago
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:
log("Building docker image");
const dockerBuild = spawn(
"docker",
["build", "-t", image, ".", "--network", "backend"],
{
cwd: cmd.REPO_BASE,
env: { DOCKER_BUILDKIT: 0 },
},
);

log("Building docker image");
const dockerBuild = spawn(
"docker",
["build", "-t", image, ".", "--network", "backend"],
{
cwd: cmd.REPO_BASE,
env: { DOCKER_BUILDKIT: 0 },
},
);

And it works but i really want to migrate all my projects to dokploy
Siumauricio
Siumauricio8mo ago
Why do you need a network?
dx
dxOP8mo ago
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.
Siumauricio
Siumauricio8mo ago
I'm getting this error when deploying the repo you've shared can you change the network to dokploy-network?
No description
dx
dxOP8mo ago
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?
iraunit
iraunit8mo ago
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.
Siumauricio
Siumauricio8mo ago
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.
dx
dxOP8mo ago
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"
Siumauricio
Siumauricio8mo ago
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.
dx
dxOP8mo ago
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:
dx
dxOP8mo ago
GitHub
GitHub - calliduslabs/backend
Contribute to calliduslabs/backend development by creating an account on GitHub.
dx
dxOP8mo ago
GitHub
GitHub - calliduslabs/frontend
Contribute to calliduslabs/frontend development by creating an account on GitHub.
Siumauricio
Siumauricio8mo ago
Hey, Thanks I will test now, I'm in my house rn
dx
dxOP8mo ago
No description
dx
dxOP8mo ago
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
dx
dxOP8mo ago
No description
dx
dxOP8mo ago
that points to the backend container.
Siumauricio
Siumauricio8mo ago
ok let me test it
dx
dxOP8mo ago
and this is the error
No description
dx
dxOP8mo ago
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.
const dockerBuild = spawn(
"docker",
["build", "-t", image, ".", "--network", "backend"],
{
cwd: cmd.REPO_BASE,
env: { DOCKER_BUILDKIT: 0 },
},
);
const dockerBuild = spawn(
"docker",
["build", "-t", image, ".", "--network", "backend"],
{
cwd: cmd.REPO_BASE,
env: { DOCKER_BUILDKIT: 0 },
},
);
`
Siumauricio
Siumauricio8mo ago
it works when using the domain BACKEND_URL="http://tersting-backend-bug-f04faf-5c882d-5-161-121-59.traefik.me"
dx
dxOP8mo ago
any reason why?
Siumauricio
Siumauricio8mo ago
probably something happen inside of nextjs using the hostname of the container it doesn't work why don't use the domain?
dx
dxOP8mo ago
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
Siumauricio
Siumauricio8mo ago
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.
dx
dxOP8mo ago
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
Siumauricio
Siumauricio8mo ago
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
dx
dxOP8mo ago
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!
Siumauricio
Siumauricio8mo ago
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
dx
dxOP8mo ago
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?
Siumauricio
Siumauricio8mo ago
Not for now
dx
dxOP8mo ago
what about this one?
Siumauricio
Siumauricio8mo ago
Hmm I think you need to run the custom installation
Eric
Eric3mo ago
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??

Did you find this page helpful?