我正在尝试在Dockerfile中执行npm install
,但即使假设禁用颜色,颜色代码似乎仍然出现在Dockerhub构建日志中。
我可能做错了什么?
您可以在Docker Hub上找到包含构建详细信息的Dockerfile:https://hub.docker.com/r/amcsi/szeremi/builds/btk4utf3whezxqhnbzpkhyw/
Dockerfile:
FROM node
MAINTAINER Attila Szeremi <attila+webdev@szeremi.com>
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 npm@3.3.12
[0m[91mnpm[0m[91m [0m[91minfo[0m[91m [0m[91musing[0m[91m node@v5.5.0
[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 npm@3.3.12
[0m[91mnpm[0m[91m [0m[91minfo[0m[91m [0m[91musing[0m[91m node@v5.5.0
[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 npm@3.3.12
[0m[91mnpm[0m[91m [0m[91minfo[0m[91m [0m[91musing[0m[91m node@v5.5.0
答案 0 :(得分:1)
对我有用的解决方案是@admin.register(Car)
class CarAdmin(CustomAdmin):
list_display = ('get_color',)
def get_color(self, obj):
return mark_safe('<a href="/admin/myapp/car/?color={}">{}</a>'.format(obj.color, obj.color))
,我在此处找到:https://github.com/nodejs/docker-node/issues/225
答案 1 :(得分:0)
FROM node
表示node 6.5(目前最近于2016年9月发布)
如issue 225中所述,它附带一个进度条(您尝试禁用)和一个微调器。
尝试简单的测试用例:
FROM node:6.4.0
ENV NPM_CONFIG_PROGRESS false
ENV NPM_CONFIG_SPIN false
WORKDIR /app
RUN npm install express
或者通过复制.npmrc:
progress=false
spin=false
或者直接将--color false
添加到npm install
命令:
npm --color false install --production
如果无效,请重新打开问题225,因为这是该问题的最新错误报告。
或者考虑使用AnsiColor Plugin在Jenkins中运行作业,至少支持f
自此回答(2016年10月)以来,问题225提到:
问题是你的Jenkins在控制台输出中不支持ANSI转义序列 Dockerfile中STDERR上的所有输出都由docker build打印为红色。正如@tianon所提到的那样,只需使用AnsiColor + Plugin就可以解决这个问题。
因此解决此问题的一种方法是忽略任何输出,如Zack Steinkamp中this comment of the issue 225 RUN npm install 2>&1
所述。