background:
I'm on Ubuntu 20.04. I'm trying to build images using docker-compose.
This is my docker-compose
file
version: "3.8"
services:
web:
build: ./frontend
network_mode: "host"
ports:
- 3000:3000
api:
build: ./backend
network_mode: "host"
ports:
- 3001:3001
environment:
DB_URL: mongodb://db/foo-app
db:
image: mongo:4.0-xenial
ports:
- 27017:27017
volumes:
- foo-app-data:/data/db
volumes:
foo-app-data:
And below are my two Dockerfile
files:
# ./backend file
FROM node:16.3.0-alpine3.13
RUN addgroup app && adduser -S -G app app
WORKDIR /app
USER root
COPY package*.json ./
# --- debug try
RUN npm cache clean --force
RUN npm config set registry https://registry.npmjs.org/
RUN npm install -g @angular/cli
# ---
RUN npm install
COPY . .
RUN chown app:app /app
USER app
EXPOSE 3001
CMD ["npm", "start"]
# ./frontend file
FROM node:16.3.0-alpine3.13
RUN addgroup app && adduser -S -G app app
WORKDIR /app
USER root
COPY package*.json ./
# --- debug try
RUN npm cache clean --force
RUN npm config set registry https://registry.npmjs.org/
# ---
RUN npm install
COPY . .
RUN chown app:app /app
USER app
EXPOSE 3000
CMD ["npm", "start"]
error:
When I run docker-compose build
, the below error is thrown:
Step 8/14 : RUN npm install -g @angular/cli
---> Running in ce221adb18f6
npm ERR! code EAI_AGAIN
npm ERR! syscall getaddrinfo
npm ERR! errno EAI_AGAIN
npm ERR! request to https://registry.npmjs.org/@angular%2fcli failed, reason: getaddrinfo EAI_AGAIN registry.npmjs.org
npm ERR! A complete log of this run can be found in:
npm ERR! /root/.npm/_logs/2021-06-13T10_19_13_600Z-debug.log
The command '/bin/sh -c npm install -g @angular/cli' returned a non-zero code: 1
ERROR: Service 'web' failed to build : Build failed
what i have tried so far:
when I was building each docker file manually, I was getting the same error, until I used the --network=host
. It means, when I build the images with docker build --network=host
, it works fine. So I tried to add network_mode= "host"
to my docker-compose file but it doesn't solve the issue.
and for God's sake, read this before marking this question as duplicate:
- this post here propose a solution for docker and not docker compose. When I
ping registry.npmjs.org
, the connection works fine. - this post here propose to
docker-compose up
, which will throw the exact same error as I have here. - this post here doens't work, i have already restarted docker multiple times. And on top of that, I clean all docker images after the error is thrown to make sure the next time I build, nothing is used from the cache.
- this post here doesn't work either. I tried to (1) remove the proxies from the npm config, and also add the additional lines
npm cache clean --force
andnpm config set registry https://registry.npmjs.org/
in my Dockerfile. Nothing works. - this post here not only doesn't solve the problem, but also it doesn't really explain well the reason why the solution is being proposed.
- and this post here i don't even know how this answer is allowed on StackOverflow.