如何在中间容器中使用NPM配置文件?

时间:2018-08-08 19:06:58

标签: node.js docker npm environment-variables npm-config

尝试时

Shortcut.add(messageField, Key.ENTER, sendButton::click);

带有以下Shortcut.add(messageField, Key.ENTER, sendButton::click, Key.SHIFT);

docker build \
--tag my-app:latest \
.

以及以下Dockerfile

FROM node:9-stretch AS intermediate

ARG NPM_TOKEN

COPY [".npmrc", "./"]

RUN ["chmod", "0600", ".npmrc"]

COPY ["package.json", "./"]

RUN ["npm", "install"]

FROM node:9-stretch

WORKDIR /usr/src/app/

COPY --from=intermediate ["node_modules/.", "./node_modules/."]

COPY ["package.json", "index.js", "./"]

CMD ["node", "index.js"]

我在.npmrc容器的步骤//registry.npmjs.org/:_authToken=${NPM_TOKEN} 中收到以下错误:

Step 6/14 : RUN ["npm", "install"]

我的intermediate中的Bash shell和Error: Failed to replace env in config: ${NPM_TOKEN} at /usr/local/lib/node_modules/npm/lib/config/core.js:417:13 at String.replace (<anonymous>) at envReplace (/usr/local/lib/node_modules/npm/lib/config/core.js:413:12) at parseField (/usr/local/lib/node_modules/npm/lib/config/core.js:391:7) at /usr/local/lib/node_modules/npm/lib/config/core.js:334:17 at Array.forEach (<anonymous>) at Conf.add (/usr/local/lib/node_modules/npm/lib/config/core.js:333:23) at ConfigChain.addString (/usr/local/lib/node_modules/npm/node_modules/config-chain/index.js:244:8) at Conf.<anonymous> (/usr/local/lib/node_modules/npm/lib/config/core.js:321:10) at /usr/local/lib/node_modules/npm/node_modules/graceful-fs/graceful-fs.js:78:16 at FSReqWrap.readFileAfterClose [as oncomplete] (fs.js:525:3) /usr/local/lib/node_modules/npm/lib/npm.js:61 throw new Error('npm.load() required') ^ Error: npm.load() required at Object.get (/usr/local/lib/node_modules/npm/lib/npm.js:61:13) at process.errorHandler (/usr/local/lib/node_modules/npm/lib/utils/error-handler.js:205:18) at process.emit (events.js:180:13) at process._fatalException (internal/bootstrap/node.js:391:27) 中的Z shell还有以下行:

.bashrc

我根据发现的here官方NPM文档,以此方式将.zshrc添加到我的Docker映像中。

1 个答案:

答案 0 :(得分:0)

您快到了!

根据您链接的NPM官方文档,export NPM_TOKEN=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx 命令中缺少的是node_modules选项,其中提到了here和详细的here

您完成的命令应该是:

docker build