简体   繁体   English

GCP Cloud Run 部署 Docker 容器未启动,因为 nginx 图像无法找到 error.log

[英]GCP Cloud Run deployed Docker container does not start because of nginx image is failing to find error.log

When I deploy my Vue.js webapp to Cloud Run it does not seems to bootstrap properly.当我将 Vue.js webapp 部署到 Cloud Run 时,它似乎无法正确引导。 Running the container locally or in a Kube.netes Pod does work as expected.在本地或 Kube.netes Pod 中运行容器确实按预期工作。

This is the Dockerfile I am using:这是我正在使用的 Dockerfile:

# build stage
FROM node:lts-alpine as build-stage
WORKDIR /app
COPY package*.json ./
RUN npm install
COPY . .
RUN npm run build

# production stage
FROM nginx:stable-alpine as production-stage
COPY --from=build-stage /app/dist /usr/share/nginx/html
EXPOSE 80
CMD ["touch", "/var/log/ngingx/error.log"]
CMD ["touch", "/var/log/ngingx/access.log"]
CMD ["nginx", "-g", "daemon off;"]

local docker build log: https://pastebin.com/1nGk2E5n本地 docker 构建日志: https://pastebin.com/1nGk2E5n

bitbucket pipeline docker build log: https://pastebin.com/d5wCj1vY bitbucket 管道 docker 构建日志: https://pastebin.com/d5wCj1vY

Cloud Run error message (actual docker container start log): Cloud Run报错信息(实际docker容器启动日志):

Deploying container to Cloud Run for Anthos service [importer-controlroom-frontend-dev] in namespace [dev] of cluster [myApp-cluster-dev]
Deploying...
Creating Revision...................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................failed
Deployment failed
ERROR: (gcloud.run.deploy) Revision "importer-controlroom-frontend-dev-00003-tum" failed with message: Container failed with: /docker-entrypoint.sh: /docker-entrypoint.d/ is not empty, will attempt to perform configuration
/docker-entrypoint.sh: Looking for shell scripts in /docker-entrypoint.d/
/docker-entrypoint.sh: Launching /docker-entrypoint.d/10-listen-on-ipv6-by-default.sh
10-listen-on-ipv6-by-default.sh: Getting the checksum of /etc/nginx/conf.d/default.conf
10-listen-on-ipv6-by-default.sh: Enabled listen on IPv6 in /etc/nginx/conf.d/default.conf
/docker-entrypoint.sh: Launching /docker-entrypoint.d/20-envsubst-on-templates.sh
/docker-entrypoint.sh: Configuration complete; ready for start up
nginx: [alert] could not open error log file: open() "/var/log/nginx/error.log" failed (2: No such file or directory)
2020/07/17 08:26:03 [emerg] 1#1: open() "/var/log/nginx/error.log" failed (2: No such file or directory)
.

Local docker container deploy log:本地docker容器部署日志:


/docker-entrypoint.sh: /docker-entrypoint.d/ is not empty, will attempt to perform configuration
/docker-entrypoint.sh: Looking for shell scripts in /docker-entrypoint.d/
/docker-entrypoint.sh: Launching /docker-entrypoint.d/10-listen-on-ipv6-by-default.sh
10-listen-on-ipv6-by-default.sh: Getting the checksum of /etc/nginx/conf.d/default.conf
10-listen-on-ipv6-by-default.sh: Enabled listen on IPv6 in /etc/nginx/conf.d/default.conf
/docker-entrypoint.sh: Launching /docker-entrypoint.d/20-envsubst-on-templates.sh
/docker-entrypoint.sh: Configuration complete; ready for start up

So I have two different outcomes.所以我有两个不同的结果。 I somewhat think that Cloud Run handles the nginx differently and I also read some blog articles about that but I just can't find out how I can bring my app to run without this mentioned issue.我有点认为 Cloud Run 对 nginx 的处理方式不同,我也阅读了一些关于此的博客文章,但我无法找到如何在没有这个问题的情况下运行我的应用程序。

My read of the error message(s) is that我读到的错误信息是

  1. you need to possibly mkdir -p /var/log/nginx before you start nginx (mkdir should not be part of your Dockerfile, but as part of your container startup ie CMD/ENTRYPOINT).在启动 nginx 之前,您可能需要mkdir -p /var/log/nginx (mkdir应该是您的 Dockerfile 的一部分,而是作为容器启动的一部分,即 CMD/ENTRYPOINT)。 Maybe this directory exists in your container image;也许这个目录存在于你的容器镜像中; but Cloud Run re-mounts a clean volume to /var/log upon startup.但 Cloud Run 在启动时将一个干净的卷重新挂载到 /var/log 。

  2. Consider not using /var/log/nginx in Cloud Run.考虑不在 Cloud Run 中使用 /var/log/nginx。 Instead, please study nginx images in Docker Hub to see how they print logs to /dev/stdout and /dev/stderr devices.相反,请研究 Docker Hub 中的 nginx 图像,了解它们如何将日志打印到 /dev/stdout 和 /dev/stderr 设备。

  3. It seems like you don't understand what CMD / ENTRYPOINT do properly.看来你不明白CMD / ENTRYPOINT的正确做法。 CMD cmd1 and CMD cmd2 isn't doing what you think it does. CMD cmd1CMD cmd2并没有按照您的想法行事。 Please spend the time and read the Docker docs on what these actually do.请花时间阅读 Docker 文档,了解它们的实际作用。

  4. It seems you have multiple commands upon startup, consider wrapping these in a bash script and set that as your ENTRYPOINT .启动时您似乎有多个命令,请考虑将它们包装在 bash 脚本中并将其设置为您的ENTRYPOINT That script would run startup commands, and would finally replace itself with nginx by doing exec nginx [...] .该脚本将运行启动命令,并最终通过执行exec nginx [...]将自身替换为 nginx。

  5. You have a typo at ngingx .你在ngingx有错字。

暂无
暂无

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

相关问题 将 docker 镜像部署到云运行时如何解决“容器启动失败错误” - How to resolve "container failed to start error" while deploying a docker image to cloud run Cloud Run 中 Docker 容器上的 POST 出现 405 错误 - 405 error for POST on Docker Container in Cloud Run 将 docker-compose 部署到 Cloud Run 或 GCP? - Deploying docker-compose to Cloud Run OR GCP? Docker 容器因“无法为新会话启动线程”错误而失败 - Docker container failing with "failed to start a thread for the new session" error “Cloud Run 错误:容器启动失败。无法启动然后侦听 PORT 环境变量定义的端口。” - "Cloud Run error: Container failed to start. Failed to start and then listen on the port defined by the PORT environment variable." Google Cloud Run - 容器无法启动解决方法 - Google Cloud Run - Container failed to start workarounds GCP AI notebooks 实际使用什么 docker 镜像? 无法从深度学习图像装载 Cloud Filestore - What docker image does GCP AI notebooks actually use? Cannot mount Cloud Filestore from the deeplearning image 记录垃圾邮件“无法找到名为 fluentd-gcp 的容器” - Log spam with "unable to find container named fluentd-gcp" 为什么 GCP Cloud Functions 会记录两个空行? - Why does GCP Cloud Functions log two blank lines? 使用 Docker 部署在 Cloud Run 上时,节点 gRPC 返回“未收到状态” - Node gRPC returns "No status received" when deployed on Cloud Run with Docker
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM