4

I am trying to build a Docker image for my Sails.js application. Here's the Dockerfile:

FROM risingstack/alpine:3.4-v8.5.0-4.7.0

ENV NODE_ENV test

RUN npm install -g sails

COPY npmrc_file .npmrc
ARG NPM_TOKEN

COPY package.json package.json
RUN npm install

RUN rm -f .npmrc

# Add your source files
COPY . .

EXPOSE 3000
CMD ["npm","start"]

I took the steps for this Dockerfile from this link on the NPM documentation site. I have made sure to match what the documentation there shows perfectly.

My docker build command is:

image="my-repo-url/tagname:tagversion"
docker build --build-arg NPM_TOKEN=my-token-goes-here -t $image -f Dockerfile .

Then I run the container with the image using docker stack or docker-compose. The container doesn't start up, due to the following error:

sails_1    | Error: Failed to replace env in config: ${NPM_TOKEN}
sails_1    |     at /usr/lib/node_modules/npm/lib/config/core.js:418:13
sails_1    |     at String.replace (<anonymous>)
sails_1    |     at envReplace (/usr/lib/node_modules/npm/lib/config/core.js:414:12)
sails_1    |     at parseField (/usr/lib/node_modules/npm/lib/config/core.js:392:7)
sails_1    |     at /usr/lib/node_modules/npm/lib/config/core.js:335:17
sails_1    |     at Array.forEach (<anonymous>)
sails_1    |     at Conf.add (/usr/lib/node_modules/npm/lib/config/core.js:334:23)
sails_1    |     at ConfigChain.addString (/usr/lib/node_modules/npm/node_modules/config-chain/index.js:244:8)
sails_1    |     at Conf.<anonymous> (/usr/lib/node_modules/npm/lib/config/core.js:322:10)
sails_1    |     at /usr/lib/node_modules/npm/node_modules/graceful-fs/graceful-fs.js:78:16
sails_1    | /usr/lib/node_modules/npm/lib/npm.js:52
sails_1    |       throw new Error('npm.load() required')
sails_1    |       ^
sails_1    |
sails_1    | Error: npm.load() required
sails_1    |     at Object.get (/usr/lib/node_modules/npm/lib/npm.js:52:13)
sails_1    |     at process.errorHandler (/usr/lib/node_modules/npm/lib/utils/error-handler.js:213:18)
sails_1    |     at emitOne (events.js:115:13)
sails_1    |     at process.emit (events.js:210:7)
sails_1    |     at process._fatalException (bootstrap_node.js:399:26)

The thing is, by the time we get to running the container, there should be no reference to or need for the ${NPM_TOKEN}. I'm using this exact same setup in another project, and don't see this error, so I'm not really sure what the deal is. I have triple checked that everything is the same in this project as the other project.

What are the possible reasons for this error and some possible solutions?

I've also read through this thread and this SO question. I feel like everything I've read has pointed me to the same solution, which I've implemented, but with no success.

pjlamb12
  • 2,300
  • 2
  • 32
  • 64

2 Answers2

3

This is what worked for me in the end:

ARG NPM_TOKEN

ENV NPM_TOKEN="${NPM_TOKEN}"

Why this solved this issue, I'm not sure!

caseylabs
  • 31
  • 2
1

This is what I am using,

in Dockerfile

ARG NPM_AUTH_TOKEN=$NPM_AUTH_TOKEN
ENV NPM_AUTH_TOKEN=$NPM_AUTH_TOKEN

and in docker-compose.yml

version: '2'
services:
  app:
    build:
      args:
        - NPM_AUTH_TOKEN
anoop
  • 3,229
  • 23
  • 35