gpt4 book ai didi

node.js - nginx:无效选项: "off"和 entrypoint.sh::权限被拒绝

转载 作者:行者123 更新时间:2023-12-02 19:44:33 25 4
gpt4 key购买 nike

我正在使用 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

最佳答案

  • 检查目录(/app)是否创建。如果不在 cfg 文件中使用以下语句并授予对该目录的权限
  • 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>

    关于node.js - nginx:无效选项: "off"和 entrypoint.sh::权限被拒绝,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64392543/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com