docker-node icon indicating copy to clipboard operation
docker-node copied to clipboard

Yarn ignores custom registry during a Docker build

Open greenled opened this issue 4 years ago • 7 comments

Environment

  • Platform: Ubuntu
  • Docker Version: 20.10.5
  • Node.js Version: 14
  • Image Tag: node:14-stretch-slim, node:14-stretch, node:14

Expected Behavior

Any of these results in a Docker layer with somepackage installed from http://customregistry.com:

  • RUN yarn add somepackage --registry http://customregistry.com
  • RUN yarn config set registry http://customregistry.com && yarn add somepackage
  • RUN YARN_REGISTRY=http://customregistry.com yarn add somepackage
  • RUN yarn add somepackage with build argument YARN_REGISTRY=http://customregistry.com

Current Behavior

In all described cases Yarn ignores the custom registry settings and tries to fetch somepackage from https://registry.yarnpkg.com. These messages are shown:

[1/4] Resolving packages...
[2/4] Fetching packages...
info There appears to be trouble with your network connection. Retrying...
info There appears to be trouble with your network connection. Retrying...
info There appears to be trouble with your network connection. Retrying...
info There appears to be trouble with your network connection. Retrying...

This makes it hard to use Yarn in Docker image builds in environments where the only available registry is a private one.

Possible Solution

Steps to Reproduce

FROM node:14-stretch-slim

RUN yarn add somepackage --registry http://customregistry.com

Additional Information

Running node:14-stretch-slim with an interactive terminal, setting custom registry by environment variable or flag, and installing somepackage works as expected.

greenled avatar Jun 04 '21 20:06 greenled

This sounds like a yarn issue rather than something with the base docker image (this repo)

nschonni avatar Jun 05 '21 22:06 nschonni

It could be the case, but I've seen it happen only in the Docker image. It works as expected with a local Yarn installation, even with this image in an interactive terminal. It only stops working during Docker builds.

Sould I open an issue in yarnpkg/yarn anyway?

greenled avatar Jun 25 '21 05:06 greenled

The network context is somewhat different in the build context. Are you using any proxy or anything?

LaurentGoderre avatar Jul 23 '21 15:07 LaurentGoderre

@LaurentGoderre No, AFAIK. http://customregistry.com is actually in the local network (.com URL was just an example for the issue).

greenled avatar Aug 13 '21 04:08 greenled

@greenled I think the default DNS for docker is 8.8.8.8 which wouldn't work for your local site. You might need to add your local DNS to the docker config.

LaurentGoderre avatar Sep 08 '21 18:09 LaurentGoderre

@LaurentGoderre I currently have it set up. I can install packages with npm during build without issues, same image. It's been a while since the last time I tried. Maybe it's already solved in a recent release. Will check it in the following days.

greenled avatar Sep 08 '21 18:09 greenled

I also encounter this issue, and I finally resolve this by replacing the endpoint in the yarn.lock. Please check here. https://stackoverflow.com/questions/48258087/how-to-use-different-yarn-registry-regardless-of-registry-in-the-yarn-lock-file

onyas avatar Sep 22 '22 02:09 onyas