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.
2
Answers
could be because of a docker network that is blocking your access
try
docker network ls
to list all networks anddocker network prune
to delete unusedand try installing again
I drop this answer here, because nothing about proxy helped in my case.
TL;DR
The version check URL redirects and that causes confusion to yarn
So, I went on to examine typical archaic tools, like verbosity check, curl and dig.
So, first thing first, I tried to check verbose output:
Bingo #1.
Why not getting an answer from yarnpkg.com? This is insane… So, let’s see if this resolves:
It does!!! (?)
So, let’s see what I get from it, by using curl
WHAT? A redirect? Ok, this is new..
I tried to set the url to check version not to be yarnpkg.com, but classic.yarnpkg.com, but I couldn’t find the yarn configuration variable to use.
So, I used
/etc/hosts
.Set the first IP to yarnpkg.com
BINGO!!! Yarn command finished instantly.