[英]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.