简体   繁体   English

GCP 上的 docker 图像(nodejs 应用程序)返回 ERR_CONNECTION_REFUSHED(在本地工作)

[英]docker image (nodejs app) on GCP returns ERR_CONNECTION_REFUSHED (works locally)

I have create a docker image from a nodejs app.我已经从 nodejs 应用程序创建了一个 docker 图像。 I want to start a VM instance with the docker image on GCP Compute Egine Instance.我想在 GCP Compute Egine 实例上启动一个带有 docker 镜像的 VM 实例。

When I test the image locally and I navigate with my browser to http://localhost:8000 , it works.当我在本地测试图像并使用浏览器导航到http://localhost:8000时,它可以正常工作。 So I don't think there is something wrong with my docker image.所以我不认为我的 docker 镜像有什么问题。

docker run -p 8000:8000 -d <username>/<docker-file>

I have pushed the docker image to google container repository with the following commands:我已经使用以下命令将 docker 镜像推送到 google 容器存储库:

docker tag <username>/<docker-file> gcr.io/<project-id>/<docker-file>
docker push gcr.io/<project-id>/<docker-file>

Now, when I add the URL (gcr.io/project-id/docker-file) to a VM instance, and I wait untill the instance is running, I get an error when I navigate to http://[instance_external_ip]:8000 , I get the error ERR_CONNECTION_REFUSED.现在,当我将 URL (gcr.io/project-id/docker-file) 添加到 VM 实例并等待实例运行时,当我导航到http://[instance_external_ip] 时出现错误: 8000 ,我收到错误 ERR_CONNECTION_REFUSED。

I have set a firewall rule to allow ingress traffic on port tcp = 8000 and IP range 0.0.0.0/0.我设置了防火墙规则以允许端口 tcp = 8000 和 IP 范围 0.0.0.0/0 上的入口流量。

Am I missing something?我错过了什么吗?

Edit:编辑:

My dockerfile我的码头文件

FROM node:10

WORKDIR /usr/src/nodejs

COPY package*.json ./

RUN npm install

COPY . .

EXPOSE 8080

CMD [ "node", "index.js" ]

In your Dockerfile you expose 8080 not 8000.在您的 Dockerfile 中,您公开的是 8080 而不是 8000。

Did you check that your container is running on the instance?您是否检查过您的容器是否正在实例上运行? tried to curl/telnet it too?也尝试 curl/telnet 吗?

How/when do you start running the docker?您如何/何时开始运行 docker? Could you run this command你能运行这个命令吗

docker run -p 8000:8000 -d gcr.io/<project-id>/<docker-file>:latest

And then try to confirm that it's running locally first using然后尝试确认它首先使用本地运行

curl localhost:8000

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

相关问题 如何在 gcp vm 中部署 docker 镜像 - how to deploy docker image in gcp vm 无法在 App Engine 标准环境 (GCP) 中部署预构建映像 - Unable to deploy pre built image in app engine standard environment (GCP) 如何在 GCP Cloud Build 的 Terraform Docker Provider 中构建和推送 docker 映像 - How to build and push a docker image in a Terraform Docker Provider by GCP Cloud Build GCP AI notebooks 实际使用什么 docker 镜像? 无法从深度学习图像装载 Cloud Filestore - What docker image does GCP AI notebooks actually use? Cannot mount Cloud Filestore from the deeplearning image 在本地运行云运行应用程序时 GCSFuse 未找到默认凭据 docker - GCSFuse not finding default credentials when running a cloud run app docker locally flutter 应用程序出现错误,可能存在互联网连接问题 - flutter app works with errors, possible internet connection issue 连接到 Cloud SQL 可以在本地运行,但不能在 App Engine 上运行 - Connection to Cloud SQL works fin on local but not on App Engine Redis 连接到 xxxx:6379 失败 - 写入 ECONNRESET。 NodeJS GCP 标准环境 - Redis connection to x.x.x.x:6379 failed - write ECONNRESET. NodeJS GCP Standard Environment 将 docker-compose 部署到 Cloud Run 或 GCP? - Deploying docker-compose to Cloud Run OR GCP? 在 gcp 上安装 docker - Installing docker on gcp
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM