'How to solve network connection when RUN yarn install in docker image build?
I have a peculiar problem occurring only in the Mac environment. When I run the docker build command to build my Node image, it is not able to fetch the packages, informing that there is a connection problem. This only occurs in the Mac environment. I have a server here where the build is done normally, but this ends up preventing me from doing tests on my machine.
Could anyone tell me what it could be and how to fix it?
Dockerfile is here:
FROM node:16.14-alpine3.15 as builder
ENV NODE_ENV=development
WORKDIR /home/node/app
COPY package*.json .
COPY yarn.lock .
COPY tsconfig.json .
RUN yarn install
COPY . .
RUN yarn build
FROM node:16.14-alpine3.15 as production
ENV NODE_ENV=production
RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app
RUN mkdir logs
COPY package*.json .
COPY yarn.lock .
RUN yarn install
COPY --from=builder /home/node/app/dist /usr/src/app/dist
EXPOSE 3333
CMD ["yarn", "start"]
I already tried adding the following flags in the yarn install command:
RUN yarn install --frozen-lockfile --no-cache --production --network-timeout 100000
All together or individually, but to no avail. I also removed the proxies, also without success.
RUN yarn config delete https-proxy RUN yarn config delete proxy.
However, I noticed that this error only occurs with v1.22 of Yarn. When using the berry version the same does not happen.
Solution 1:[1]
could be because of a docker network that is blocking your access
try docker network ls
to list all networks and docker network prune
to delete unused
and try installing again
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | gautam |