Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Docker cannot Build without access to database - ERROR (payload): Error: cannot connect to MongoDB. Details: getaddrinfo ENOTFOUND mongo #6330

Closed
Nathan-Nesbitt opened this issue May 12, 2024 · 1 comment
Labels
status: needs-triage Possible bug which hasn't been reproduced yet

Comments

@Nathan-Nesbitt
Copy link

Link to reproduction

No response

Describe the Bug

Currently trying to build and deploy an docker image for payload. Maybe there is a different process in mind for how to deploy this to production, but my flow is:

1. Commit code to main 
2. CI builds the image with the changes to the site 
3. Deploy to docker image repository 
4. CD pulls this image and deploys it to an already running cluster

Now when I go to build the project using the Dockerfile it looks that it is trying to access the database during build:

 > [builder 2/2] RUN yarn build:
0.557 yarn run v1.22.19
0.580 $ cross-env NODE_ENV=production yarn build:payload && yarn build:server && yarn copyfiles && yarn build:next
0.755 $ cross-env PAYLOAD_CONFIG_PATH=src/payload/payload.config.ts payload build
16.94 $ tsc --project tsconfig.server.json
19.88 $ copyfiles -u 1 "src/**/*.{html,css,scss,ttf,woff,woff2,eot,svg,jpg,png}" dist/
20.23 $ cross-env PAYLOAD_CONFIG_PATH=dist/payload/payload.config.js NEXT_BUILD=true node dist/server.js
53.35 [22:30:01] ERROR (payload): Error: cannot connect to MongoDB. Details: getaddrinfo ENOTFOUND mongo
53.38 error Command failed with exit code 1.
53.38 info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
53.40 error Command failed with exit code 1.
53.40 info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

Which makes this not possible as you cannot deploy without already having access to the DB. Meaning either the CI pipeline has to be within the cluster with the MongoDB instance, or you have to expose the MongoDB instance outside the cluster to the CI pipeline.

Is there any way to build this as an image, then deploy? Or is this a limitation that this cannot be used in Swarm/K8s?

Is it possible to have the DB scripts run once the image has deployed, instead of having them run while building?

Thanks! :)

To Reproduce

  1. Clone the demo website.
  2. Update the .env file to have valid values
  3. Run docker build .

Payload Version

2.13.0

Adapters and Plugins

No response

@Nathan-Nesbitt Nathan-Nesbitt added the status: needs-triage Possible bug which hasn't been reproduced yet label May 12, 2024
@Nathan-Nesbitt
Copy link
Author

Nathan-Nesbitt commented May 14, 2024

I'm actually going to close this as it may be better to address this on the demo github repo in a conversation, as it's more geared towards the demo than the actual library :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: needs-triage Possible bug which hasn't been reproduced yet
Projects
None yet
Development

No branches or pull requests

1 participant