首页 > 解决方案 > Gcloud app deploy 不能忽略 Dockerfile

问题描述

我通常将我的NodeJS应用程序部署到 Google App Engine 并在通过文件部署时忽略所有 docker 资产,.gcloudignore如下所示:

.git
.gitignore
Dockerfile
docker-compose.yml
nginx/
redis-data/
.vscode/
.DS_Store
.prettierrc
README.md
node_modules/
.env

上周我成功地将我的应用程序部署到 App Engine,没有任何问题。但是今天(除了源代码没有任何更改)它失败并给我一个错误:

ERROR: (gcloud.app.deploy) There is a Dockerfile in the current directory, and the runtime field in /Users/tranphongbb/Works/unstatic/habitify-annual-report-backend/app.yaml is currently set to [runtime: nodejs]. To use your Dockerfile to build a custom runtime, set the runtime field to [runtime: custom]. To continue using the [nodejs] runtime, please remove the Dockerfile from this directory.

即使删除.gcloudignore文件并使用 中的skip_files选项app.yaml,它仍然失败。

我的源代码树

.dockerignore
.eslintrc.json
.gcloudignore
.gitignore
.prettierrc
.vscode
Dockerfile
README.md
app.yaml
docker-compose.yml
nginx
package.json
src

标签: node.jsdockergoogle-app-enginegcloud

解决方案


我通过克隆 Node.js App Engine Flex Quickstart 并将 Dockerfile 添加到与 app.yaml 文件相同的文件夹中重现了您的问题。确实,我收到了与您相同的错误消息。但是我可以看到,如果我将 Dockerfile 移动到不同的目录,则部署成功。似乎 gcloud app deploy 不尊重 .gcloudignore 文件。

对于柔性环境中的 node.js, App Engine 官方文档中没有 skip_files 条目。

要忽略 .gcloudignore 文件中定义的文件,请运行gcloud beta app deploy在 app.yaml 中使用 Nodejs Runtime 时对我有用的命令以忽略 Dockerfile,或者您可以使用gcloud app deploy命令但将 Dockerfile 移动到另一个目录。


推荐阅读