[英]nginx: invalid option: "off" and entrypoint.sh: : Permission denied
我正在使用 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
RUN mkdir -p /app
RUN chmod -R 777 /app
#!/bin/sh
set -e
chmod -R 777 /app
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
入口点脚本:
#!/bin/sh
while true; do sleep 120; done
复制命令:
docker cp <entry point script path> <container_name>:<path to copy the script in container>
docker restart <container_name>
我花了几个小时。 最新版本的 nginx 镜像需要调用 /docker-entrypoint.sh
# my entrypoint
# do something
# do another thing
#....
# DON't run "exec $@" directly but run:
exec /docker-entrypoint.sh $@
不要玩CMD。 将其保留为默认值。
从 nginx 1.19 开始,默认入口点中有很多功能可以让我摆脱自定义入口点。
例如:支持 nginx 配置模板文件
默认.conf.template
http {
listen ${MY_PORT}
}
文件
FROM nginx:1.19-alpine
ENV MY_PORT=80
COPY default.conf.template /etc/nginx/templates/
构建它然后运行:
docker run myimage
#--> will run on 80 ( see dockerfile)
docker run -e MY_PORT=8080 myimage
#--> will run on 8080 ( see -e MY_PORT)
如果你对这个特性的逻辑特别好奇,exec 到容器,查看这个脚本的内容/docker-entrypoint.d/20-envsubst-on-templates.sh
更多细节:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.