MongooseServerSelectionError: getaddrinfo EAI_AGAIN mongodb #568
Replies: 4 comments 2 replies
-
Your same issue? https://www.reddit.com/r/mongodb/comments/x5h9cw/mongooseserverselectionerror_getaddrinfo_eai/ Seems like the mongo container isn't running, what do the logs show for that one? I'm not able to reproduce with your docker-compose file $ docker-compose up -d
Creating mongo_mongodb_1 ... done
Creating mongo_mongo-express_1 ... done
$ docker-compose logs 2>&1 | tail -n 5
mongodb_1 | {"t":{"$date":"2022-09-06T16:02:09.195+00:00"},"s":"I", "c":"NETWORK", "id":23015, "ctx":"listener","msg":"Listening on","attr":{"address":"0.0.0.0"}}
mongodb_1 | {"t":{"$date":"2022-09-06T16:02:09.195+00:00"},"s":"I", "c":"NETWORK", "id":23016, "ctx":"listener","msg":"Waiting for connections","attr":{"port":27017,"ssl":"off"}}
mongodb_1 | {"t":{"$date":"2022-09-06T16:02:11.667+00:00"},"s":"I", "c":"NETWORK", "id":22943, "ctx":"listener","msg":"Connection accepted","attr":{"remote":"172.27.0.3:50582","uuid":"ee51f193-d383-4c21-b60a-8a6fbd0bd881","connectionId":1,"connectionCount":1}}
mongodb_1 | {"t":{"$date":"2022-09-06T16:02:11.681+00:00"},"s":"I", "c":"NETWORK", "id":51800, "ctx":"conn1","msg":"client metadata","attr":{"remote":"172.27.0.3:50582","client":"conn1","doc":{"driver":{"name":"nodejs","version":"3.7.3"},"os":{"type":"Linux","name":"linux","architecture":"x64","version":"4.19.0-18-amd64"},"platform":"'Node.js v12.22.7, LE (legacy)"}}}
mongodb_1 | {"t":{"$date":"2022-09-06T16:02:11.712+00:00"},"s":"I", "c":"ACCESS", "id":20250, "ctx":"conn1","msg":"Authentication succeeded","attr":{"mechanism":"SCRAM-SHA-256","speculative":true,"principalName":"admin","authenticationDatabase":"admin","remote":"172.27.0.3:50582","extraInfo":{}}} You could also try asking over at the Docker Community Forums, Docker Community Slack, or Stack Overflow. Since these repos aren't really a user-help forum |
Beta Was this translation helpful? Give feedback.
-
yeah same issue here also
it is establishing a proper connection and I can access the databases from the compass but when the dockerfile script runs and the server starts everything goes right until the db connection and no matter what type of DB URI I use the same error pops up
One solution I did found for this which is flushing the entire DNS cache collection of the docker instance and then restart the docker containers but the issue is I can't seem to figure out how to do that. |
Beta Was this translation helpful? Give feedback.
-
In addition to version: "3"
services:
mongodb:
image: mongo
ports:
- 27017:27017
environment:
- MONGO_INITDB_ROOT_USERNAME=admin
- MONGO_INITDB_ROOT_PASSWORD=password
mongo-express:
image: mongo-express
depends_on:
- mongodb
links:
- mongodb
restart: always
ports:
- 8080:8081
environment:
- ME_CONFIG_MONGODB_ADMINUSERNAME=admin
- ME_CONFIG_MONGODB_ADMINPASSWORD=password
- ME_CONFIG_MONGODB_SERVER=mongodb
# - ME_CONFIG_MONGODB_HOSTNAME=localhost |
Beta Was this translation helpful? Give feedback.
-
I still have the problem version: "3.8"
services:
booking_system_service:
build:
context: .
dockerfile: ./Dockerfile
stop_signal: SIGINT
container_name: booking_system_service
environment:
POSTGRES_HOST: ${POSTGRES_HOST}
POSTGRES_PORT: ${POSTGRES_PORT}
POSTGRES_USER: ${POSTGRES_USER}
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
POSTGRES_DB: ${POSTGRES_DB}
POSTGRES_CONNECTION_URL: ${POSTGRES_CONNECTION_URL}
MONGO_PORT: ${MONGO_PORT}
MONGO_DB_HOST: ${MONGO_DB_HOST}
MONGO_DB_NAME: ${MONGO_DB_NAME}
MONGO_CONNECTION_URL: ${MONGO_CONNECTION_URL}
APP_PORT: ${APP_PORT}
ports:
- "127.0.0.1:${APP_PORT}:${APP_PORT}"
volumes:
- .:/app
depends_on:
- booking_system_postgres_db_service
- booking_system_mongodb_service
links:
- booking_system_postgres_db_service
- booking_system_mongodb_service
network_mode: "host"
restart: always
booking_system_postgres_db_service:
image: postgres:13.15
container_name: booking_system_postgres_db_service
environment:
POSTGRES_USER: ${POSTGRES_USER}
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
POSTGRES_DB: ${POSTGRES_DB}
volumes:
- /var/lib/postgresql/data:/var/lib/postgresql/data
network_mode: "host"
restart: unless-stopped
healthcheck:
test: ["CMD-SHELL", "pg_isready -U ${POSTGRES_USER}"]
interval: 10s
timeout: 5s
retries: 5
booking_system_mongodb_service:
image: mongo:latest
container_name: booking_system_mongodb
environment:
MONGO_DB_NAME: ${MONGO_DB_NAME}
MONGO_DB_HOST: ${MONGO_DB_HOST}
volumes:
- /data/db:/data/db
network_mode: "host"
restart: unless-stopped
healthcheck:
test: ["CMD-SHELL", "mongo --eval 'db.runCommand({ connectionStatus: 1 })'"]
interval: 10s
timeout: 5s
retries: 5 Dockerfile # Stage 1: Build
FROM node:20.14.0 As build
WORKDIR /app
COPY package.json ./
COPY tsconfig.json ./
COPY src ./src
RUN npm install
RUN npm run build
RUN rm -rf .npmrc
# Stage 2: Production
FROM node:lts-alpine@sha256:34b7aa411056c85dbf71d240d26516949b3f72b318d796c26b57caaa1df5639a As production
RUN apk add dumb-init
RUN npm install -g nodemon
ENV NODE_ENV=production
# Create necessary directories and set permissions
RUN mkdir -p /app/var/lib/postgresql/data /app/data/db && \
chown -R node:node /app/var/lib/postgresql/data /app/data/db
USER node
WORKDIR /app
COPY --chown=node:node --from=build /app/node_modules ./node_modules
COPY --chown=node:node --from=build /app/dist ./dist
COPY --chown=node:node . /app
EXPOSE 5000
CMD ["dumb-init", "npm", "run", "dev"] .env
|
Beta Was this translation helpful? Give feedback.
-
Good day sir.
Please assist me with this issue when connecting mongo docker to the mongoose to start the server. I'm new to docker and I'm trying to connect mongo docker to mongoose but apparently, things are not working so well. Your assistance would be highly appreciated.
mongo.yaml
server.js
Thank you.
Beta Was this translation helpful? Give feedback.
All reactions