Using ARG in my Dockerfile but still getting "Failed to replace env in config" when running my build

460 Views Asked by At

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?

1

There are 1 best solutions below

1
On BEST ANSWER

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

Ref here