首页 > 解决方案 > 浏览 Docker 托管的应用程序时出现 ERR_CONNECTION_REFUSED

问题描述

我开发了一个 Node.js 应用程序。我可以使用它运行它node bin/www,然后我可以在浏览器上通过http://localhost:3000/访问它。

然后我将它 dockerized,但尝试在浏览器上访问它http://localhost:3000/显示 ERR_CONNECTION_REFUSED。

我可以通过运行看到容器docker ps

CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS
       NAMES
9301a87c47af        hello-express       "/bin/sh -c 'node bi…"   4 minutes ago       Up 2 minutes        0.0.0.0:3000->3000
/tcp   admiring_torvalds

Dockerfile:

FROM node:7
WORKDIR /app
COPY package.json /app
RUN npm install
COPY . /app
CMD node bin/www
EXPOSE 3000

我在 Windows 10 上工作并使用 Docker Toolbox。

标签: node.jsdocker

解决方案


In Docker Toolbox, a container is implemented as a VM. This VM has a different IP address. I used Kinematic (a GUI for Docker Toolbox) to find the IP address of the VM and then reached it on the browser via its IP rather than localhost.


推荐阅读