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