How to use an NPM Registry Connection inside a Docker build?

I'm trying to setup a build for a javascript app. The build needs to package into a docker image.  As part of the docker build it needs to run "npm ci" against a custom NPM registry. 

Now I can create an NPM registry connection and add an NPM Registry connection build feature.  These presumably are making an API token available somewhere.

I can't figure out how to expose that token inside a docker build.  The problem is that I can't find where it's exposed at all.  I've checked through every place I can think including environment variables on the buld process (checked through /proc/.../environ), local .npmrc files in every directory I can guess.

My real goal here is simply to expose this connection inside a docker build but I'm bashing my head against a brick wall trying to figure it out.

1
1 comment

Hi! As hinted in the documentation, the NPM Registry Connection and the respective build feature only affect the Node.js build step at the time of writing.

If you want the script executed by `docker build` to use a private registry, you will need to ensure the .npmrc file with the registry information exists and is passed to the image.

One of the ways to pass it to the image is using RUN --mount=type=secret,id=npmrc,target=<project_dir_inside_the_image>/.npmrc npm install  in Dockerfile, and by adding the --secret id=npmrc,src=<dir_on_docker_host>/.npmrc argument to the Additional arguments for the command field of the “docker build” step.
More info about this approach is given here:
https://docs.npmjs.com/docker-and-private-modules 

0

Please sign in to leave a comment.