docker-node
docker-node copied to clipboard
Yarn ignores custom registry during a Docker build
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.comRUN yarn config set registry http://customregistry.com && yarn add somepackageRUN YARN_REGISTRY=http://customregistry.com yarn add somepackageRUN yarn add somepackagewith 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.
This sounds like a yarn issue rather than something with the base docker image (this repo)
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?
The network context is somewhat different in the build context. Are you using any proxy or anything?
@LaurentGoderre No, AFAIK. http://customregistry.com is actually in the local network (.com URL was just an example for the issue).
@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 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.
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