1

I have this file (.npmrc.docker)

//registry.npmjs.org/:_authToken=${NPM_TOKEN}

And in my Docker file I have

ARG NPM_TOKEN
RUN mv .npmrc.docker .npmrc
RUN yarn install

However when I run my Docker build with

NPM_TOKEN=mySecretToken docker build .

I get this error

#41 0.710 error An unexpected error occurred: "Failed to replace env in config: ${NPM_TOKEN}".

What’s the proper way to pass an environment variable into my Docker build?

Dave
  • 15,639
  • 133
  • 442
  • 830

1 Answers1

1

docker build --build-arg NPM_TOKEN=mySecretToken . should do the job

Ref here

ale917k
  • 1,494
  • 7
  • 18
  • 37
  • 1
    to complement your answer, here is the [documentation](https://docs.docker.com/engine/reference/commandline/build/#set-build-time-variables---build-arg) – edocollado Jun 08 '22 at 18:27