[英]How do I map a port on a container to the host?
I'm trying to run a container described by the following Dockerfile: 我正在尝试运行以下Dockerfile描述的容器:
FROM node:11.4.0
RUN npm install -g sh
RUN npm install -g json-server
WORKDIR /data
VOLUME /data
COPY db.json /data
CMD json-server --watch db.json --port 3001
and specifying the listening port by running: 并通过运行以下命令指定侦听端口:
docker run -it -p 3001:3001 abelalejandro/json-server:final
The container seems to be running fine and json-server is telling me it is serving my requests on port 3001 yet I can't get any joy when browsing http://localhost:3001 该容器似乎运行良好,并且json-server告诉我它正在端口3001上处理我的请求,但浏览http:// localhost:3001时我无法获得任何喜悦
Am I missing something on publishing/exposing ports? 我在发布/公开端口上缺少什么吗?
It is binding to localhost
instead of 0.0.0.0
(any host). 它绑定到localhost
而不是0.0.0.0
(任何主机)。
You can change that by setting: 您可以通过设置来更改它:
CMD json-server --watch db.json --host 0.0.0.0 --port 3001
I'm assuming you are using https://github.com/typicode/json-server . 我假设您正在使用https://github.com/typicode/json-server 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.