无法从Docker Container内部连接到Redis / Memcache

时间:2016-09-28 15:34:33

标签: docker redis memcached docker-machine

我有一个Docker Image,它封装了我们开发环境的所有工具。但是,在某些配置文件中运行应用程序将尝试连接到外部Redis / Memcache服务器。

但是,它无法与这些服务器建立连接。在容器内部进行ping操作时,它会为主机找到正确的IP,但它表示主机无法访问:

ping HOST
PING HOST (CORRECT.IP) 56(84) bytes of data.
From e856591c01e7 (172.17.0.3) icmp_seq=1 Destination Host Unreachable
From e856591c01e7 (172.17.0.3) icmp_seq=2 Destination Host Unreachable
From e856591c01e7 (172.17.0.3) icmp_seq=3 Destination Host Unreachable
From e856591c01e7 (172.17.0.3) icmp_seq=4 Destination Host Unreachable
From e856591c01e7 (172.17.0.3) icmp_seq=5 Destination Host Unreachable
From e856591c01e7 (172.17.0.3) icmp_seq=6 Destination Host Unreachable

ping或卷曲其他网站,如谷歌或Facebook,工作完全正常。

DockerMachine是网络设置的默认设置。在Mac OSX 10.10.5,Docker 1.12.1,Docker-Machine 0.8.1

上运行

有什么想法吗?我不知所措。

4 个答案:

答案 0 :(得分:0)

Docker正在使用不同的网络模式。您可以尝试在"主机网络"中运行您的容器,这样它将与运行docker-machine的主机共享网络连接:

 docker run --net=host your_image and other options

答案 1 :(得分:0)

docker ps的输出是什么?你是如何运行容器的?

答案 2 :(得分:0)

对于将来遇到此问题的任何人,请尝试使用ipv6建立docker网络并打开端口。我没有得到它的工作,但我很确定这是正确的道路。

答案 3 :(得分:0)

如果上述可能的解决方案不起作用。也许你应该检查memcache服务器配置是否有收听的IP地址。

memcache机器是另一个docker容器还是用于memcache的单独独立服务器?

如果您希望连接到主机的内存缓存服务器,则可能需要配置内存缓存以允许来自本地IP以外的IP地址的连接。

如果你正在使用ubuntu(或类似的)编辑配置;

import UIKit

class ViewController: UIViewController,UIViewControllerTransitioningDelegate {

    let blurModalPresentation = BlurModalPresentation()

    override func viewDidLoad() {
        super.viewDidLoad()

    }

    func showVC(){

        let str = self.storyboard!
        let vc = str.instantiateViewController(withIdentifier: "YourViewControllerIdentifier")
        vc.transitioningDelegate = self
        self.present(vc, animated: true, completion: nil)
    }


    override func viewDidAppear(_ animated: Bool) {
        super.viewDidAppear(animated)
    }

    func animationController(forPresented presented: UIViewController, presenting: UIViewController, source: UIViewController) -> UIViewControllerAnimatedTransitioning?{

        return blurModalPresentation
    }


    func animationController(forDismissed dismissed: UIViewController) -> UIViewControllerAnimatedTransitioning?{

        return blurModalPresentation
    }

}

找到以" -l 127.0.0.1"开头的行通过用逗号分隔来添加客户端计算机的IP地址。

例如,如果要从172.17.0.3和172.18.0.3进行连接,则替换为;

nano /etc/memcached.conf