[英]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我读到的错误信息是
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 。
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 设备。
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 cmd1
和CMD cmd2
并没有按照您的想法行事。 Please spend the time and read the Docker docs on what these actually do.请花时间阅读 Docker 文档,了解它们的实际作用。
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。
You have a typo at ngingx
.你在
ngingx
有错字。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.