Docker容器无法连接到链接的容器服务

编程入门 行业动态 更新时间:2024-10-26 08:30:27
本文介绍了Docker容器无法连接到链接的容器服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我在Ubuntu 14.04服务器主机上使用Docker 1.9.1 build a34a1d5,我有4个容器:redis(基于alpine linux 3.2),mongodb(基于alpine linux 3.2),postgres(基于ubuntu 14.04) )和将运行连接到其他容器的应用程序的容器(基于alpine linux 3.2)。所有的数据库容器都在Dockerfile中公开其相应的端口。

I'm using Docker version 1.9.1 build a34a1d5 on an Ubuntu 14.04 server host and I have 4 containers: redis (based on alpine linux 3.2), mongodb (based on alpine linux 3.2), postgres (based on ubuntu 14.04) and the one that will run the application that connects to these other containers (based on alpine linux 3.2). All of the db containers expose their corresponding ports in the Dockerfile.

我对数据库容器进行了修改,因此它们的服务不绑定到本地主机IP,而是绑定到所有地址。这样,我将能够从应用程序容器连接到所有这些。 为了进行测试,我先运行数据库容器,然后运行具有以下命令的应用程序:

I did the modifications on the database containers so their services don't bind to the localhost IP but to all addresses. This way I would be able to connect to all of them from the app container. For the sake of testing, I first ran the database containers and then the app one with a command like the following:

docker run --rm --name app_container --link mongodb_container --link redis_container --link postgres_container -t localhost:5000/app_image

我输入了应用容器的终端,并确认其/ etc / hosts文件包含其他容器的IP和名称。然后,我可以ping所有数据库容器。但是我无法将它们的端口连接到任何db容器。

I enter the terminal of the app container and I verify that its /etc/hosts file contains the IP and names of the other containers. Then I am able to ping all the db containers. But I cannot connect to their ports to any of the db containers.

一个简单的例子: telnet mongodb_container 27017 并永远等待,如果我尝试连接到其他数据库容器,也会发生同样的情况。如果我运行该应用程序,它还会抱怨它无法连接到指定的数据库服务。

A simple: telnet mongodb_container 27017 simply sits and waits forever, and the same happens if I try to connect to the other db containers. If I run the application, it also complains that it cannot connect to the specified db services.

重要提示:我可以通过telnet主机中所有数据库容器的相应端口。

Important note: I am able to telnet the corresponding ports of all the db containers from the host.

可能会发生什么?

编辑::我将包含数据库容器的运行命令:

I'll include the run commands for the db containers:

docker run --rm --name mongodb_container -t localhost:5000/mongodb_image docker run --rm --name redis_container -t localhost:5000/redis_image docker run --rm --name postgres_container -t localhost:5000/postgres_image

推荐答案

好,telnet的问题似乎与telnet客户端有关在高山linux上,因为以下两个命令显示了容器上的端口是打开的:

Well, the problem with telnet seems to be related to the telnet client on alpine linux since the following two commands showed me that the ports on the containers were open:

nmap -p27017 172.17.0.3 nc -vz 172.17.0.3 27017

主要关注我发出的elnet命令,我相信问题与端口关闭或其他原因有关;而且我忽略了用于将其连接到服务的应用程序上的配置文件(文件名错误),我的错。

Being focused mainly on the telnet command I issued, I believed that the problem was related to the ports being closed or something; and I overlooked the configuration file on the app that was being used to connect it to the services (it was the wrong filename), my bad.

现在一切正常。

更多推荐

Docker容器无法连接到链接的容器服务

本文发布于:2023-10-18 12:10:45,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1504194.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:容器   连接到   链接   Docker

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!