'EAI_AGAIN error while installing yarn packages with Docker and VPN

I am trying to run yarn install inside a docker container, and having this Dockerfile:

FROM node:16-alpine

ARG API_USER_TOKEN
ENV API_USER_TOKEN=$API_USER_TOKEN

WORKDIR /home/node/app
RUN chown -R node:node /home/node
USER node

COPY package.json yarn.lock .npmrc ./

RUN yarn install

COPY nest-cli.json tsconfig.json tsconfig.build.json ./

EXPOSE 9000 50051

CMD ["yarn", "start:dev"]

All i get, is this error while fetching yarn packages:

error An unexpected error occurred: "https://registry.yarnpkg.com/cron-parser: getaddrinfo EAI_AGAIN registry.yarnpkg.com".

I'm connected to work VPN and working on Ubuntu, and i believe it's a VPN related issue. So far i tried this:

  1. Copying DNS adresses from /etc/resolv.conf file to /etc/docker/daemon.json and restarting docker service.
  2. Trying openconnect and Cisco Anyconnect.
  3. Setting docker network to host instead of bridge.

What could be the issue here?



Solution 1:[1]

Please try to append for example Google DNS inside docker /etc/resolv.conf like the following:

# ... previous DNS servers
nameserver 8.8.8.8

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 czeski