1

How can I view network adapter associated to container.

I launched an application that starts 50 docker containers and created 50 "virtual" network adapters on my Ubuntu 18.04 system.

I can view network adapters with ifconfig -a. It shows ipv6 but not ipv4. I can also view docker container ipv4 with docker inspect, but not ipv6.

I haven't figured out a way to associate a network adapter with a docker container.

Jesus H
  • 1,180
  • 3
  • 13
  • 25

2 Answers2

1

You can check the interface ifindex of the veth pair:

brctl show docker0

To see the veth interfaces in the docker bridge, Now using this script you can see which interface your container is using:

#!/bin/bash

for i in $(ip link list | awk -F '@' '/veth/ {split($2,a,":"); print a[1]}' | sed 's/if//g');do
  for dock in $(docker ps --quiet);do
    dock_index=$(docker exec -ti $dock cat /sys/class/net/eth0/ifindex | sed 's/\r$//')
    if [[ $i == $dock_index ]]; then
       echo "$i $dock"
    fi
  done
done
c4f4t0r
  • 1,563
  • 15
  • 24
0

Run this command to find you docker network id:

docker network ls --no-trunc

NETWORK ID                                                         NAME                DRIVER              SCOPE
1849dpjmcnj7ckw4q2svhvj4r                                          base_default        overlay             swarm

And then inspect it:

docker inspect <container_name> | grep "1849dpjmcnj7ckw4q2svhvj4r"
                        "Target": "1849dpjmcnj7ckw4q2svhvj4r",
                    "NetworkID": "1849dpjmcnj7ckw4q2svhvj4r",
Batchen Regev
  • 685
  • 1
  • 7
  • 28