Search code examples
dockerdocker-swarm

Swarm mode: Inspect worker node's container on manager node


I was wondering if it is possible to inspect a container running on a worker node from the manager node? The container was created via docker service create. From the manager node, I can get the task's service id (via docker service ps and even the container id (via docker inspect ) My end goal is being able to find the container's ip address. Any help would be much appreciated!

Additional info:

Docker version 1.12.1

OS: CentOS Linxus 7


Solution

  • There is no direct way to get that yet. You're supposed to just forget about dealing with ip's and rely on resolving using dns names (service names).

    If you really want though, you could create a script that does the following.

    1. Get the tasks ID's and their node names for your service.

      docker service ps myservice
      

      That will return something like

      ID                         NAME   IMAGE       NODE        DESIRED STATE  CURRENT STATE           ERROR
      31cb7clxw3lfi1y6ko12edjys  foo.1  alpine:3.4  vmw-node03  Running        Running 30 minutes ago  
      9gkzs118txbc8a8gvla3bildq  foo.2  alpine:3.4  vmw-node01  Running        Running 30 minutes ago
      

      The service has two tasks running on different nodes.

    2. Get the Container ID's for each task

      I'm just doing it for one task here

      docker inspect --format "{{.Status.ContainerStatus.ContainerID}}" 31cb7clxw3lfi1y6ko12edjys
      

      Which will return the container id for the task

      13a24dff4bd1f9351938b09d32db451406ed64b5f890f66f18fec12c611e9175
      
    3. Get the Container IP

      docker $(docker-machine config vmw-node03) inspect --format "{{.NetworkSettings.IPAddress}}" 13a24dff4bd1f9351938b09d32db451406ed64b5f890f66f18fec12c611e9175 
      

      Which returns it

      172.17.0.2