【发布时间】:2021-01-31 04:12:57
【问题描述】:
我正在使用 Dockerfile 创建构建,然后通过 jenkins 作业部署该构建/映像,但容器状态为“CrashLoopBackOff”,当我检查日志时,出现以下错误..
错误:-
nginx: invalid option: "off"
/etc/nginx/entrypoint.sh: 5: /etc/nginx/entrypoint.sh: : Permission denied
注意:- 授予 entrypoint.sh 的完全权限。 (检查 dockerfile)
Dockerfile:-
FROM node:12.18.4-alpine AS BUILD_IMAGE
WORKDIR /app
# add `/app/node_modules/.bin` to $PATH
ENV PATH /app/node_modules/.bin:$PATH
COPY package.json .
COPY package-lock.json .
COPY .npmrc .
RUN npm install
COPY . .
RUN npm run build
FROM nginx:latest
RUN apt-get update
RUN apt-get -y install sudo
COPY --from=BUILD_IMAGE /app/build /usr/share/nginx/html
COPY nginx/nginx.conf /etc/nginx/conf.d/default.conf
COPY .build/envs/uat/env.js /app/uat/env.js
COPY .build/envs/prod/env.js /app/prod/env.js
COPY entrypoint.sh /etc/nginx/entrypoint.sh
RUN sudo chmod 777 /etc/nginx/entrypoint.sh
RUN sudo nginx -t
RUN ls -lrt /etc/nginx/
EXPOSE 80
ENTRYPOINT ["/etc/nginx/entrypoint.sh"]
# replace ENVIRONMENT with uat, prod
CMD ["ENVIRONMENT"]
entrypoint.sh 文件:-
#!/bin/sh
set -e
if [ "$1" = 'uat' ]; then
"$(cp /app/uat/env.js /usr/share/nginx/html && nginx -g daemon off;)"
elif [ "$1" = 'prod' ]; then
"$(cp /app/prod/env.js /usr/share/nginx/html && nginx -g daemon off; )"
fi
【问题讨论】:
-
'daemon off;'需要被引用才能成为一个shell word。 -
(我建议使用
docker run -v绑定挂载在部署时注入适当的配置文件,并使用基础nginx映像中的命令。您也可以完全删除sudo从这个设置。)
标签: node.js linux bash docker nginx