英文:
Can't expose web server using docker on OSX
问题
我有一个运行Web服务器的Docker镜像,我想从我的本地OSX访问它,但是我遇到了问题。
我使用以下命令启动容器:docker run -p 8000:8000 <container-name>
我可以看到日志消息告诉我本地服务器正在监听localhost:8000
我可以通过运行以下命令获得成功的响应:
docker exec <IMAGE-ID> curl "http://localhost:8000/"
我在本地OSX上尝试的地址有:
http://localhost:8000/
http://<DOCKER-IP-172.17.0.2:8000/
这两个都不起作用。有什么建议吗?
- 容器是从
golang:1.8
构建的 - Docker版本:
Version 17.03.1-ce-mac5 (16048)
- MacOS Sierra:
10.12.4
- 防火墙已关闭以进行测试
我在Ubuntu 16.04上尝试了相同的过程,也没有成功。
英文:
I have a docker image that runs a webserver and I would like to access it from my local OSX, but I'm having issues.
I start the container with: docker run -p 8000:8000 <container-name>
and I can see log messages telling me that the local server is listening on localhost:8000
I am able to get a successful response from running:
docker exec <IMAGE-ID> curl "http://localhost:8000/"
Addresses I've tried on my local OSX are:
http://localhost:8000/
http://<DOCKER-IP-172.17.0.2:8000/
Neither of those work. Any suggestions?
- Container is built from
golang:1.8
- Docker Version:
Version 17.03.1-ce-mac5 (16048)
- MacOS Sierra:
10.12.4
- Firewall is turned off for testing purposes
I've tried the same process on Ubuntu 16.04 and no luck their either.
答案1
得分: 2
较新版本的Docker在OSX上使用vpnkit
来管理对容器的端口转发...如果你想暴露容器端口,你应该允许vpnkit通过你的防火墙。
此外,在你的Go代码中,确保将Web服务器代码绑定到0.0.0.0
而不是127.0.0.1
。
英文:
The newer versions of docker use vpnkit
on OSX to manage the port forwarding to the containers... you should allow vpnkit through your firewall if you want to expose the container ports.
Also, in your Go code, make sure to bind to 0.0.0.0
rather than 127.0.0.1
for your webserver code.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论