Access IP address of Couchbase container on Docker Swarm cluster

0 votes

Trying to run a Couchbase cluster on Docker Swarm cluster. 

Once the cluster is started, I want to obtain the IP address of each Couchbase instance dynamically. 

docker inspect gives this:

"NetworkSettings": {
        "Bridge": "",
        "SandboxID": "325807d55b552be3fe5b44b4d975c2486b3a56b320aa56fa0367e42348b82d64",
        "HairpinMode": false,
        "LinkLocalIPv6Address": "",
        "LinkLocalIPv6PrefixLen": 0,
        "Ports": {
            "11207/tcp": null,
            "11210/tcp": [
                {
                    "HostIp": "192.168.99.101",
                    "HostPort": "11210"
                }
            ],

Trying to access the IP address gives the error:

docker inspect --format '{{ .NetworkSettings.Ports.8091/tcp[0].HostIp }}' 922755302fef
Template parsing error: template: :1: unexpected ".8091" in operand; missing space?
Aug 24, 2018 in Docker by lina
• 8,220 points
775 views

1 answer to this question.

0 votes

The property .NetworkSettings.Ports is a map, not a struct. You can use the index template function to access the map values:

$ docker inspect --format '{{ index .NetworkSettings.Ports "8091/tcp" 0 "HostIp" }}'
answered Aug 24, 2018 by Nilesh
• 7,050 points

Related Questions In Docker

+4 votes
4 answers

How To Access a Service on Host From a Docker Container?

Adding to kalgi's answer, You can also ...READ MORE

answered Oct 16, 2018 in Docker by lina
• 8,220 points

edited Oct 16, 2018 by lina 33,031 views
0 votes
1 answer
+2 votes
1 answer
+5 votes
7 answers

Docker swarm vs kubernetes

Swarm is easy handling while kn8 is ...READ MORE

answered Aug 27, 2018 in Docker by Mahesh Ajmeria
3,153 views
0 votes
1 answer

Init could not choose ip address error while doing docker swarm init

First look for the public IP of ...READ MORE

answered Aug 23, 2018 in Docker by Nilesh
• 7,050 points
3,092 views
0 votes
2 answers

Can't access apache karaf docker container

To access karaf shell directly you can ...READ MORE

answered Aug 6, 2018 in Docker by Nilesh
• 7,050 points
2,120 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP