2020年12月25日星期五

Having trouble connecting to mongo image on my ubuntu instance

MongoServerSelectionError: getaddrinfo ENOTFOUND mongo

is the error I'm getting when I try to run docker-compose build.

This is my docker-compse.yml file

version: '3'  services:    app:      container_name: node-app      build: .      ports:        - "3000:3000"      restart: always      volumes:        - ./uploads:/app/uploads      links:        - mongo    mongo:      container_name: mongo      image: mongo      volumes:        - ./data:/data/db      ports:        - "27017:27017"      command: mongod  

as well as my Dockerfile

# https://docs.docker.com/samples/library/node/  ARG NODE_VERSION=12.10.0  # https://github.com/Yelp/dumb-init/releases  ARG DUMB_INIT_VERSION=1.2.2    # Build container  FROM node:${NODE_VERSION}-alpine AS build  ARG DUMB_INIT_VERSION    WORKDIR /home/node    RUN apk add --no-cache build-base python2 yarn && \      wget -O dumb-init -q https://github.com/Yelp/dumb-init/releases/download/v${DUMB_INIT_VERSION}/dumb-init_${DUMB_INIT_VERSION}_amd64 && \      chmod +x dumb-init  ADD . /home/node  RUN yarn install && yarn build && yarn cache clean    # Runtime container  FROM node:${NODE_VERSION}-alpine    WORKDIR /home/node    COPY --from=build /home/node /home/node    EXPOSE 3000  CMD ["./dumb-init", "yarn", "start"]  

My connection string in the code is mongodb://mongo:27017/{db_name}

When I run docker ps -a, I can clearly that my mongo image is there. I've googled this issue to no extent, and tried ridiculous combinations of connection strings to try and connect to mongo, but does anyone have any supplemental information or debugging advice to overcome this?

https://stackoverflow.com/questions/65453355/having-trouble-connecting-to-mongo-image-on-my-ubuntu-instance December 26, 2020 at 11:07AM

没有评论:

发表评论