简体   繁体   English

nginx:无效选项:“关闭”和 entrypoint.sh::权限被拒绝

[英]nginx: invalid option: "off" and entrypoint.sh: : Permission denied

I am creating build using Dockerfile and then deploying that build/image via jenkins job but container status is "CrashLoopBackOff" and when I am checking the logs, below error occurs..我正在使用 Dockerfile 创建构建,然后通过 jenkins 作业部署该构建/映像,但容器状态为“CrashLoopBackOff”,当我检查日志时,出现以下错误..

Error:-错误:-

nginx: invalid option: "off"
/etc/nginx/entrypoint.sh: 5: /etc/nginx/entrypoint.sh: : Permission denied 

Note:- Full permission given to entrypoint.sh.注意:- 授予 entrypoint.sh 的完全权限。 (check the dockerfile) (检查dockerfile)

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 file:- 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
  1. Check the directory(/app) is created or not.检查目录(/app)是否创建。 If not use the below statement in the cfg file and give permissions to that directory如果不在 cfg 文件中使用以下语句并授予该目录的权限
RUN mkdir -p /app

RUN chmod -R 777 /app
  1. Give permissions in the entry point script also还要在入口点脚本中授予权限
#!/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
  1. For the container to spin up use an infinite loop in the entry point script and copy it to the respective location and restart the container and then can debug为了使容器启动,在入口点脚本中使用无限循环并将​​其复制到相应位置并重新启动容器,然后可以调试

Entry point script:入口点脚本:

#!/bin/sh
while true; do sleep 120; done

Copy command:复制命令:

docker cp <entry point script path> <container_name>:<path to copy the script in container>

docker restart <container_name>

I spent couple of hours.我花了几个小时。 last versions of nginx images requires calling /docker-entrypoint.sh最新版本的 nginx 镜像需要调用 /docker-entrypoint.sh

# my entrypoint

# do something
# do another thing
#....

# DON't run "exec $@" directly but run:
exec /docker-entrypoint.sh $@

Do not play with CMD.不要玩CMD。 keep it as the default.将其保留为默认值。

imporant point: since nginx 1.19重要的一点:从 nginx 1.19 开始

since nginx 1.19, there are a lot of features in the default entrypoint which lets me to get rid off my custom entrypoints.从 nginx 1.19 开始,默认入口点中有很多功能可以让我摆脱自定义入口点。

eg: support of nginx config templates files例如:支持 nginx 配置模板文件

default.conf.template默认.conf.template


http {
  listen ${MY_PORT}

}

Dockerfile文件

FROM nginx:1.19-alpine
ENV MY_PORT=80
COPY default.conf.template /etc/nginx/templates/

build it then run:构建它然后运行:

docker run myimage
#--> will run on 80 ( see dockerfile)
docker run -e MY_PORT=8080 myimage
#--> will run on 8080 ( see -e MY_PORT)

If you are curious about the logic of this feature specifically, exec to the container and check the content of this script /docker-entrypoint.d/20-envsubst-on-templates.sh如果你对这个特性的逻辑特别好奇,exec 到容器,查看这个脚本的内容/docker-entrypoint.d/20-envsubst-on-templates.sh

More details:更多细节:

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 sh:1:节点:权限被拒绝 - sh: 1: node: Permission denied sh: 1: rimraf: 实时服务器上的权限被拒绝问题 - sh: 1: rimraf: Permission denied issue on live server Heroku:“bash:./start.sh:权限被拒绝” - Heroku: “bash: ./start.sh: Permission denied” "sh: 1: cross-env: laravel mix 的权限被拒绝" - sh: 1: cross-env: Permission denied on laravel mix Heroku 构建失败 [sh: 1: react-scripts: Permission denied] - Heroku Build Fail [sh: 1: react-scripts: Permission denied] 通过 Google Cloud 构建触发器进行部署“sh: 1: jest: Permission denied” - Deploying via Google Cloud build trigger "sh: 1: jest: Permission denied" sh: 1: tailwindcss: Permission denied // 构建过程中的错误 Tailwindcss CLI - sh: 1: tailwindcss: Permission denied // error on build process Tailwindcss CLI nginx:index.js“被禁止(13:权限被拒绝) - nginx: index.js" is forbidden (13: Permission denied) WSL2 节点:npm install cpu-features -&gt; npm ERR! /bin/sh: 1: cmake: 权限被拒绝 - WSL2 Node: npm install cpu-features -> npm ERR! /bin/sh: 1: cmake: Permission denied sh:1:node-gyp-build:权限被拒绝和 npm ERR! 代码 ELIFECYCLE npm 错误! 错误号 126 - sh: 1: node-gyp-build: Permission denied and npm ERR! code ELIFECYCLE npm ERR! errno 126
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM