简体   繁体   English

使用Java连接到Docker上的多节点Couchbase集群

[英]Connect to a multi node Couchbase cluster on Docker in Java

I created a first couchbase server with the following command: 我使用以下命令创建了第一个Sofabase服务器:

docker run -d --name db1 -p 8091-8094:8091-8094 -p 11210:11210 couchbase

The second server I created without the parameters for port because otherwise docker can't deploy the container: 我创建的第二个服务器没有端口参数,因为否则docker无法部署容器:

docker run -d --name db2 couchbase

Now I can access the web console of the first container and create a cluster with the second container. 现在,我可以访问第一个容器的Web控制台,并使用第二个容器创建集群。

The problem is that I can't connect to the created cluster in Java because port 11210 is not published for the second container. 问题是我无法连接到Java中创建的群集,因为没有为第二个容器发布端口11210。 I'm always getting a TimeoutException . 我总是得到一个TimeoutException How can I solve this? 我该如何解决?

You will have to expose the ports for the second container too, just as you did in first container (those "parameters" are port mappings). 您也必须expose第二个容器的端口,就像在第一个容器中一样(这些“参数”是端口映射)。

Most likely, you were unable to run the second container with parameters because you tried mapping the same ports as you did in first container; 最有可能的是,您无法使用参数运行第二个容器,因为您尝试映射的端口与第一个容器中的端口相同。 aka, you tried this command: aka,您尝试了以下命令:

docker run -d --name db2 -p 8091-8094:8091-8094 -p 11210:11210 couchbase

This wouldn't work because you cannot use ports that are already being used. 这将不起作用,因为您不能使用已经使用的端口。 So try mapping to different set of ports. 因此,尝试映射到不同的端口集。 For example: 例如:

docker run -d --name db2 -p 9091-9094:8091-8094 -p 11210:11210 couchbase

Notice how I am now using 9091-9094 instead of 8091-8094 . 注意我现在如何使用9091-9094而不是8091-8094 The above command means: map ports 8091-8094 from the container to ports 9091-9094 in the host . 上面的命令意味着: map ports 8091-8094 from the container to ports 9091-9094 in the host Any requests sent to 9091-9094 on host will be forwarded to 8091-8094 inside container automatically. 发送到主机上的9091-9094任何请求都将自动转发到8091-8094内的8091-8094

And then you can connect to your second container by specifying the new ports ( 9091-9094 ). 然后,您可以通过指定新端口( 9091-9094 )连接到第二个容器。

I suggest you to check the docker basics, especially the documentation for port mapping . 我建议您检查Docker基础知识,尤其是port mapping的文档。

Finally I could solve the problem by setting up virtual machines for the servers with vagrants . 最后,我可以解决通过与服务器建立虚拟机的问题流浪 This way it is no problem to have multiple Couchbase instances with the same ports. 这样,拥有多个具有相同端口的Couchbase实例是没有问题的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Couchbase群集 - 1个节点关闭时的异常 - Couchbase cluster - exception when 1 node is down Java如何使用jedis连接到Docker Redis集群实例? - How to connect to a Docker Redis cluster instance using jedis for Java? Couchbase群集:一个节点向下=>整个群集向下? - Couchbase Cluster: one node down => entire cluster down? 节点死亡时如何使用Java客户端连接Redis集群 - How to java client connect Redis cluster when the node died 无法将 Java 中编写的 Kafka 生产者连接到远程集群节点 - Unable to connect Kafka producer written in Java to remote cluster node Couchbase Java SDK中有没有一种方法可以不列出要连接的节点? - Is there a way in the Couchbase Java SDK to not list the nodes to connect to? 使用Java连接到Oracle集群 - Connect to an Oracle cluster in Java Couchbase群集 - 发现Java SDK2的不可用服务器 - Couchbase cluster - discover unavailable servers for Java SDK2 Couchbase:使用 Java SDK 3 列出集群中可用的桶、范围和集合 - Couchbase : List available Buckets, scopes and collection available in a Cluster with Java SDK 3 无法使用 Java API 连接到在本地虚拟机上运行的 ElasticSearch Docker 集群 - Can't connect to ElasticSearch Docker cluster which run on local virtual machine using Java API
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM