首页 > 解决方案 > 错误后退在 nginx pod 中重新启动失败的容器

问题描述

使用 kubernetes 部署 nginx 映像的简单用例

用于创建镜像的 Dockerfile。dockerfile COPY语句中的“./build/”,是reactjs代码的输出目录(npm run build),里面就是静态文件。

FROM nginx
COPY ./build/ /usr/share/nginx/html/ 
RUN rm -f /etc/nginx/conf.d/default.conf
COPY ./default.conf /etc/nginx/conf.d/
CMD ["nginx"]
EXPOSE 80 

为什么在nginx部署中会出现这个错误?错误是“后退重启失败的容器”。 手动运行容器,但 nginx 没有运行。我可以手动启动 nginx。我是否缺少 Dockerfile 或 /etc/nginx/conf.d/default.conf 文件中的任何配置?文件被复制并在github路径中可用以供参考。

root@desktop:~/github/nginx-app# docker run -it private.registry.corp/company-dev-poc/nginx-cms:001 bash
root@fc7ebd431ae2:/# service nginx status
[FAIL] nginx is not running ... failed!

标签: nginxkubernetesdockerfile

解决方案


采用CMD ["nginx", "-g", "daemon off;"]

此外,您不需要指定命令。CMD 和 EXPOSE 将在基础映像中定义 - 在本例中为 nginx。它们不需要再次定义。


推荐阅读