0

Here is my Dockerfile. Once I execute it throws an errorconnect ECONNREFUSED 172.17.0.1:27017 kindly help me out in this regard. Thank you.

FROM node:18-alpine
RUN npm install --global nodemon

RUN apk upgrade --update-cache --available && \
    apk add openssl && \
    apk add git && \
    rm -rf /var/cache/apk/*
RUN openssl version
RUN node --version

ENV MONGO_URI=mongodb://172.17.0.1:27017/dbname

RUN mkdir -p /home/node/app/node_modules && chown -R node:node /home/node/app
WORKDIR /home/node/app
COPY ./package.json ./

USER node
RUN npm install;    

USER root
RUN apk del git
USER node
COPY --chown=node:node . ./

EXPOSE 8080
CMD ["npm","start"]
tadman
  • 208,517
  • 23
  • 234
  • 262
  • Your host system is not necessarily 172.17.0.1, depending on the host OS and Docker networking setup. [From inside of a Docker container, how do I connect to the localhost of the machine?](https://stackoverflow.com/questions/24319662/from-inside-of-a-docker-container-how-do-i-connect-to-the-localhost-of-the-mach) describes some other approaches. Also consider running MongoDB in a sibling container rather than directly on the host, and setting `$MONGO_URI` when you launch the container rather than baking its value into your image. – David Maze Oct 13 '22 at 10:28
  • 1
    Please describe the *technical problem* in your title, not that you're having a problem and need help. We get that, you're on Stack Overflow. – tadman Oct 14 '22 at 08:30
  • You should customize `MONGO_URI` to match what you've actually got running with the `-e` option, or your Docker Compose config. – tadman Oct 14 '22 at 08:31

0 Answers0