docker nginx容器没有从外部接收请求,连接被拒绝 [英] docker nginx container not receiving request from outside, connection refused

查看:1990
本文介绍了docker nginx容器没有从外部接收请求,连接被拒绝的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个运行的nginx容器:#docker run --name mynginx1 -P -d nginx ;



并通过 docker ps 获得其端口信息: 0.0.0.0:32769->80/tcp,0.0.0.0:32768->443 / tcp



然后我可以从容器内获取响应(id:c30991a04b2f):




  • docker exec -i -t c3099 bash


  • curl http:// localhost =>它返回默认的 index.html 页面内容, / p>




但是,当我使 curl http:// localhost:32769 在容器外面,我得到这个:



curl:(7)无法连接到本地主机端口32769:连接拒绝






我正在Mac上运行Docker版本1.9.0; nginx最新的



有谁知道是什么原因造成的?任何帮助?谢谢

解决方案

如果您是在OSX上,您可能在Docker环境中使用VirtualBox VM。



确保你有将您的端口32769 转发到您的实际主机(mac),以便该端口从本地主机可见。

这对旧的boot2docker或新的docker机器有效。

  VBoxManage controlvmboot2docker-vm--natpf1tcp-port32769,tcp ,, 32769,,32769
VBoxManage controlvmboot2docker-vm--natpf1udp-port32769,udp ,, 32769 ,, $ 32769

controlvm 如果虚拟机正在运行, modifyvm 是VM已停止)

(替换 boot2docker-vm 您的vm的名称:请参阅 docker-machine ls



我建议不要使用 -P ,而是静态端口映射 -p xxx:80 -p yyy:443

这样,您可以使用固定值执行一次端口转发。 p>

当然,您可以通过 docker-machine ip vmname


$直接访问VM b $ b

  curl http:// $(docker-machine ip vmname):32769 


I have a running nginx container: # docker run --name mynginx1 -P -d nginx;

And got its PORT info by docker ps: 0.0.0.0:32769->80/tcp, 0.0.0.0:32768->443/tcp

Then I could get response from within the container(id: c30991a04b2f):

  • docker exec -i -t c3099 bash

  • curl http://localhost => which return the default index.html page content, it works

However, when I make the curl http://localhost:32769 outside of the container, I got this:

curl: (7) failed to connect to localhost port 32769: Connection refused


I am running on a mac with docker version 1.9.0; nginx latest

Does anyone know what cause this? Any help? thank you

解决方案

If you are On OSX, you are probably using a VirtualBox VM for your docker environment.

Make sure you have forwarded your port 32769 to your actual host (the mac), in order for that port to be visible from localhost.
This is valid for the old boot2docker, or the new docker machine.

VBoxManage controlvm "boot2docker-vm" --natpf1 "tcp-port32769  ,tcp,,32769,,32769"
VBoxManage controlvm "boot2docker-vm" --natpf1 "udp-port32769 ,udp,,32769,,$32769

(controlvm if the VM is running, modifyvm is the VM is stopped)
(replace "boot2docker-vm" b ythe name of your vm: see docker-machine ls)

I would recommend to not use -P, but a static port mapping -p xxx:80 -p yyy:443.
That way, you can do that port forwarding once, using fixed values.

Of course, you can access the VM directly through docker-machine ip vmname

curl http://$(docker-machine ip vmname):32769

这篇关于docker nginx容器没有从外部接收请求,连接被拒绝的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆