无法连接到Docker映像中的Node

时间:2018-11-25 11:55:12

标签: docker

我已经使用此Docker文件创建了一个映像...

FROM node:8

# Create application directory
WORKDIR /usr/src/app

# Install application dependencies
# By only copying the package.json file here, we take advantage of cached Docker layers
COPY package.json ./
RUN npm install
# This will install dev dependencies as well. 
# If dev dependencies have been set, use --only-production when deploying to production

# Bundle app source code
COPY . .

EXPOSE 3000

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

但是当我使用$ docker run -d --rm -p 3000:3000 62运行它时,我无法使用curl http://localhost:3000/About来从Docker主机(OS X)从容器中运行在容器内运行的API

如果我执行到容器中,我会通过cUrl从API得到有效的响应。容器中看起来像是Linux防火墙,但我看不到正在运行。

有什么想法吗?

1 个答案:

答案 0 :(得分:3)

您的节点服务器很可能没有在所有接口上侦听,请确保它绑定到0.0.0.0而不是127.0.0.1