我正在尝试在Dockerfile中执行npm install,但是即使据说禁用颜色,颜色代码似乎仍会出现在Dockerhub构建日志中。

我可能做错了什么?

您可以在Docker Hub上找到包含构建细节的Dockerfile:https://hub.docker.com/r/amcsi/szeremi/builds/btk4utf3whezxqhnbzpkhyw/

Dockerfile:

FROM node
MAINTAINER  Attila Szeremi <[email protected]>
RUN mkdir /src
WORKDIR /src
RUN cd /src
# Copy just the package.json file file as a cache step.
COPY package.json /src/package.json
# Disable progress so npm would install faster.
# Disable colors, because Dockerhub can't display them.
# Install NPM packages excluding the dev dependencies.
RUN npm set progress=false && npm set color=false && npm install --production

COPY . .
RUN npm run build
EXPOSE  8080
CMD ["npm", "run", "start"]

构建脚本输出的样本:
Step 3 : WORKDIR /src
 ---> Running in 4a8ec4902bee
 ---> ce66cec7780b
Removing intermediate container 4a8ec4902bee
Step 4 : RUN cd /src
 ---> Running in 561c6d10cdb8
 ---> c12b27e7c01a
Removing intermediate container 561c6d10cdb8
Step 5 : COPY package.json /src/package.json
 ---> ebbb940c8911
Removing intermediate container c39be008ad46
Step 6 : RUN npm set progress=false && npm set color=false && npm install --production
 ---> Running in c9ebee32f367
[91mnpm[0m[91m [0m[91minfo[0m[91m [0m[91mit worked if it ends with[0m[91m ok
[0m[91mnpm[0m[91m [0m[91minfo[0m[91m [0m[91musing[0m[91m [email protected]
[0m[91mnpm[0m[91m [0m[91minfo[0m[91m [0m[91musing[0m[91m [email protected]
[0m[91mnpm[0m[91m [0m[91minfo[0m[91m [0m[91mconfig[0m[91m set "progress" "false"
[0m[91mnpm[0m[91m [0m[91minfo[0m[91m ok
[0m[91mnpm[0m[91m [0m[91minfo[0m[91m [0m[91mit worked if it ends with[0m[91m ok
[0m[91mnpm[0m[91m [0m[91minfo[0m[91m [0m[91musing[0m[91m [email protected]
[0m[91mnpm[0m[91m [0m[91minfo[0m[91m [0m[91musing[0m[91m [email protected]
[0m[91mnpm[0m[91m [0m[91minfo[0m[91m [0m[91mconfig[0m[91m set "color" "false"
[0m[91mnpm[0m[91m [0m[91minfo[0m[91m [0m[91mok[0m[91m
[0m[91mnpm[0m[91m [0m[91minfo[0m[91m [0m[91mit worked if it ends with[0m[91m ok
[0m[91mnpm[0m[91m [0m[91minfo[0m[91m [0m[91musing[0m[91m [email protected]
[0m[91mnpm[0m[91m [0m[91minfo[0m[91m [0m[91musing[0m[91m [email protected]

最佳答案

对我有用的解决方案是npm install 2>&1,可以在这里找到:https://github.com/nodejs/docker-node/issues/225

关于docker - npm install在Docker Hub上的安装过程中显示颜色,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/35073533/

10-11 07:07