Couchbase Docker Container Network Accessibility

Looking for steps for configuring couchbase docker containers so that it is accessible from other hosts in the network.

Created a three node couchbase docker container cluster.

Commands used to start the containers:-

docker run -d --name mydb1 -p -p couchbase:community
docker run -d --name mydb2 -p -p couchbase:community
docker run -d --name mydb3 -p -p couchbase:community

netstat output :-

netstat -an|grep 8091

tcp 0 0* LISTEN
tcp 0 0* LISTEN
tcp 0 0* LISTEN

docker inspect command output :-

docker inspect --format ‘{{ .NetworkSettings.IPAddress }}’ mydb1

docker inspect --format ‘{{ .NetworkSettings.IPAddress }}’ mydb2

docker inspect --format ‘{{ .NetworkSettings.IPAddress }}’ mydb3

The above are the docker assigned IPs of each node.

I am able to access couchbase console from each of the following url from outside of the container host.

But when I write a java program using couchbase java SDK to connect to the remote cluster I get the following message mentioning the IP which is an internal docker IP. After sometime I get timeout exception.

May 02, 2017 1:55:39 PM com.couchbase.client.core.node.CouchbaseNode
WARNING: DNS Reverse Lookup of is slow, took 4500ms

The code snippet I have used to connect to remote couchbase cluster is

public static final String bucketName = "my-test-bucket";
public static final String bucketPassword = "";
public static final List<String> nodes = Arrays.asList("","","")

CouchbaseEnvironment couchEnv = DefaultCouchbaseEnvironment.builder()
cluster = CouchbaseCluster.create(Env,nodes);
bucket = cluster.openBucket(bucketName, bucketPassword);

Please note that the external machines do not have access to docker internal IPs.

Need help in getting the docker configuration right so that the external java clients can access the couchbase cluster.

Use --net=host when creating the container, so the container is started in hosts network namespace and it has the same IP address as the host VM. This should also be the best solution, performance wise, and you don’t have to do port mapping, which is a pain, since Couchbase uses many ports.

So the full command to start Couchbase container would be:
docker run -d --name mydb1 --net=host couchbase:community

If you for some reason can’t do that, then it should be possible to configure Couchbase using hostnames, but that’s a little more complicated when running in Docker container (you have to make sure that both Couchbase server and clients are using the same hostname, but it resolves to different IPs inside and outside of the container). My experience is that using --net=host is the best solution.

Thanks for the reply.

I tried the above command but unfortunately the the container does not expose any port.

I used the “docker port mydb1” command to verify it. Do I have to build my own docker image and expose specific ports?

No, when using --net=host, you don’t need port mapping. The application behaves as if it was started outside of container. However, when using --net=host, you can’t have multiple Couchbase containers running on the same node (because of port collisions). If you use --net=host, you use only node IP addresses (, .2, .3), not container IP addresses (, .3, .4).

Did you try connecting to the container using node IP address? Are Couchbase ports listed in the output of netstat -nltp?

Unfortunately did not find the ports listed. I have a requirement of running multiple containers on a single host. Is there any alternative way to overcome the issue?