skip to Main Content

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?

enter image description here

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


  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

    Login or Signup to reply.
  2. 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.

    verbose 0.181073051 Performing "GET" request to "https://yarnpkg.com/latest-version".
    [1/4] Resolving packages...                                                       
    success Already up-to-date.                                                                                                                                          
    Done in 0.12s.                                                                                                                                                       
    info There appears to be trouble with your network connection. Retrying...                                                                                           
    verbose 33.254841183 Performing "GET" request to "https://yarnpkg.com/latest-version".                                                                               
    info There appears to be trouble with your network connection. Retrying...                                                                                           
    verbose 66.292530305 Performing "GET" request to "https://yarnpkg.com/latest-version".                                                                               
    info There appears to be trouble with your network connection. Retrying...                                                                                           
    verbose 99.329186881 Performing "GET" request to "https://yarnpkg.com/latest-version".                                                                               
    info There appears to be trouble with your network connection. Retrying...                                                                                           
    verbose 132.366749502 Performing "GET" request to "https://yarnpkg.com/latest-version".
    

    Why not getting an answer from yarnpkg.com? This is insane… So, let’s see if this resolves:

    $ dig yarnpkg.com
    
    ; <<>> DiG 9.18.7-1+b1-Debian <<>> yarnpkg.com
    ;; global options: +cmd
    ;; Got answer:
    ;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 55602
    ;; flags: qr rd ra; QUERY: 1, ANSWER: 2, AUTHORITY: 0, ADDITIONAL: 1
    
    ;; OPT PSEUDOSECTION:
    ; EDNS: version: 0, flags:; udp: 4096
    ; COOKIE: 9cf3b6f8b290069dbbe8ca8763501b11ea79617323c673e6 (good)
    ;; QUESTION SECTION:
    ;yarnpkg.com.                   IN      A
    
    ;; ANSWER SECTION:
    yarnpkg.com.            300     IN      A       104.18.126.100
    yarnpkg.com.            300     IN      A       104.16.171.99
    
    ;; Query time: 11 msec
    ;; SERVER: 192.168.1.1#53(192.168.1.1) (UDP)
    ;; WHEN: Wed Oct 19 18:43:13 EEST 2022
    ;; MSG SIZE  rcvd: 100
    

    It does!!! (?)

    So, let’s see what I get from it, by using curl

    $ curl https://yarnpkg.com/latest-version
    Redirecting to https://classic.yarnpkg.com/latest-version
    

    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.

    
    ; <<>> DiG 9.18.7-1+b1-Debian <<>> classic.yarnpkg.com
    ;; global options: +cmd
    ;; Got answer:
    ;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 35092
    ;; flags: qr rd ra; QUERY: 1, ANSWER: 3, AUTHORITY: 0, ADDITIONAL: 1
    
    ;; OPT PSEUDOSECTION:
    ; EDNS: version: 0, flags:; udp: 4096
    ; COOKIE: 72636a6924283d51c4127a8463501bbb42e53d34835e8402 (good)
    ;; QUESTION SECTION:
    ;classic.yarnpkg.com.           IN      A
    
    ;; ANSWER SECTION:
    classic.yarnpkg.com.    300     IN      CNAME   yarnpkg.netlify.com.
    yarnpkg.netlify.com.    20      IN      A       3.64.200.242
    yarnpkg.netlify.com.    20      IN      A       34.141.11.154
    
    ;; Query time: 59 msec
    ;; SERVER: 192.168.1.1#53(192.168.1.1) (UDP)
    ;; WHEN: Wed Oct 19 18:46:03 EEST 2022
    ;; MSG SIZE  rcvd: 138
    
    

    Set the first IP to yarnpkg.com

    # /etc/hosts
    34.141.48.9     yarnpkg.com
    

    BINGO!!! Yarn command finished instantly.

    $ yarn 
    yarn install v1.22.19
    [1/4] Resolving packages...
    success Already up-to-date.
    Done in 0.12s.
    $
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search