-1

I have this Dockerfile

FROM node:14

WORKDIR /app

COPY package.json .

RUN npm install

COPY . .

EXPOSE 3000

CMD [ "node", "app.mjs" ]

And I can successfully run

docker run hello-world

on my ubuntu 20.10 OS. So I am assuming that docker is installed successfully. But when I tried to run

docker build .

It gives me this error

enter image description here

This is not something with the npm. I can locally install the dependencies without any issue. I assume Dokcer can't access npm registry to pull the npm packages. Something to do with networks I guess.

How do I fix this issue?

This is my code https://github.com/Enuri-Information-Systems/docker-test

margherita pizza
  • 6,623
  • 23
  • 84
  • 152
  • It seems like the network configuration for the container isn't correct. Are you able to access the internet from inside the container? – jabaa Sep 13 '21 at 09:38
  • 1
    Your Dockerfile is correct. The problem is neither in the Dockerfile nor in your project. The link to the project doesn't help here. [Here](https://stackoverflow.com/questions/40182121/whats-the-source-of-error-getaddrinfo-eai-again) are some related answers, e.g. _"EAI_AGAIN is a DNS lookup timed out error, means it is a network connectivity error or proxy related error."_ and _"If you get this error from within a docker container, e.g. when running npm install inside of an alpine container, the cause could be that the network changed since the container was started."_ – jabaa Sep 13 '21 at 09:43
  • 1
    You could try to add `--network=host` with your build command `docker build --network=host .` – t.niese Sep 13 '21 at 10:15
  • @t.niese this works! Can you add this as the answer? Then I can mark as the correct answer. – margherita pizza Sep 13 '21 at 10:51
  • I was searching for a duplicate because I'm pretty sure that this must have been asked already. In the hope that the answers there explain under which circumstance this could happen. That's why I haven't written an answer. But I can't find a question here that is actually a duplicate. – t.niese Sep 13 '21 at 11:45
  • Please post the error messages as text. – Dave Newton Sep 13 '21 at 11:50

1 Answers1

1

Depending on the network configuration it could happen that you run into problems that the container is not able to connect to a server to download data. This can have various reasons and also depends on how you run docker.

One common thing is that your network requires the usage of a proxy. But only having the error message it is not possible to tell what the exact reason in your case is.

One solution to that problem is to specify the network mode. Adding --network host as an option should most of the time work.

So running your build command that way docker build --network=host . should work.

t.niese
  • 39,256
  • 9
  • 74
  • 101