适用于Mac 1.12.0的Docker:如何从容器连接到主机 [英] Docker for mac 1.12.0: how to connect to host from container

查看:102
本文介绍了适用于Mac 1.12.0的Docker:如何从容器连接到主机的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在os x 10.10上更新了docker,因此它现在使用os x本机虚拟化.但是,我发现很难从nginx容器中连接到主机.我试过了:

I've updated docker on my os x 10.10, so it's now using os x native virtualization. However, I've found it tricky to connect to my host machine from within my nginx container. I tried this:

/sbin/ip route|awk '/default/ { print $3 }'

得到答案:

172.17.0.1

然后我在docker-compose.yml中使用了这个IP:

Then I used this ip in docker-compose.yml:

  extra_hosts:
    - "master:172.17.0.1" 

但尽管如此,我仍然收到错误消息:

But nonetheless I keep getting errors:

172.17.0.1 - - [21/Jul/2016:09:33:46 +0000] "GET /api HTTP/1.1" 502 575 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.103 Safari/537.36" "-" 2016/07/21 09:33:46 [error] 7#7: *1 connect() failed (111: Connection refused) while connecting to upstream, client: 172.17.0.1, server: soc-credit.ru, request: "GET /api HTTP/1.1", upstream: "http://172.17.0.5:8080/api", host: "localhost"

172.17.0.1 - - [21/Jul/2016:09:33:46 +0000] "GET /api HTTP/1.1" 502 575 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.103 Safari/537.36" "-" 2016/07/21 09:33:46 [error] 7#7: *1 connect() failed (111: Connection refused) while connecting to upstream, client: 172.17.0.1, server: soc-credit.ru, request: "GET /api HTTP/1.1", upstream: "http://172.17.0.5:8080/api", host: "localhost"

请注意以下部分:client: 172.17.0.1.由于我已经从主机发出请求,因此证明我第一步中获得的ip是正确的.但是仍然没有建立连接.

Please note this part: client: 172.17.0.1. Since I've made request from host machine, it proves that ip I got in first step was correct. But connection wasn't established anyway.

我想强调一下,从FROM WITHIN容器连接到主机时遇到问题,反之亦然.

I want to stress out that I have a problem connecting FROM WITHIN container TO host and not vice versa.

我做错了什么?谢谢!

推荐答案

我遇到了同样的问题,并且发现了这个问题

I am having the same problem and I've found this

https://docs.docker.com/docker-for-mac/networking/#/known-limitations-use-cases-and-workarounds

注意段落我想从容器连接到主机上的服务"

Notice paragraph 'I want to connect from a container to a service on the host'

我还没有尝试过,因为我正在寻找更具体的解决方案(除了在别名中添加别名之外)...

I haven't yet tried it because I am looking for a more concrete solution (anyway other than adding alias to my lo address)...

如果有人在上面,请告知!

If somebody has something on it please inform!

这篇关于适用于Mac 1.12.0的Docker:如何从容器连接到主机的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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