woonizzooni

Docker Container IP 확인, 네트워크 정보 조회 본문

Docker

Docker Container IP 확인, 네트워크 정보 조회

woonizzooni 2019. 6. 20. 00:13

 

 

  • 특정 Container의 IP를 찾고 싶다면,
    1) docker inspect '컨테이너이름' -f "{{json .NetworkSettings.Networks }}"
    2) 컨테이너에 ip명령으로 정보조회
1)
docker inspect mysonarqube -f "{{json .NetworkSettings.Networks }}"
{
  "bridge":{
      "IPAMConfig":null,
      "Links":null,
      "Aliases":null,
      "NetworkID":"799f0**",
      "EndpointID":"**0af086eb68e",
      "Gateway":"172.17.0.1",
      "IPAddress":"172.17.0.6",
      "IPPrefixLen":16,"IPv6Gateway":"",
      "GlobalIPv6Address":"",
      "GlobalIPv6PrefixLen":0,
      "MacAddress":"02:42:ac:11:00:06",
      "DriverOpts":null
  }
}


2)
docker exec mysonarqube ip addr show | grep inet
    inet 127.0.0.1/8 scope host lo
    inet 172.17.0.6/16 brd 172.17.255.255 scope global eth0

docker exec mysonarqube ip addr show lo
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever

docker exec mysonarqube ip addr show eth0
15: eth0@if16: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default 
    link/ether 02:42:ac:11:00:06 brd ff:ff:ff:ff:ff:ff link-netnsid 0
    inet 172.17.0.6/16 brd 172.17.255.255 scope global eth0
       valid_lft forever preferred_lft forever

 

  • Container다수의 정보를 찾고 싶다면 네트워크별 컨테이너의 IP를 찾자 (이게 가장 편한 듯)
    1) Docker network ls 
    2) Docker network inpect '네트워크이름' -f "{{ json. .Containers }}"

  1) docker network ls명령으로 네트워크 찾기

docker network ls
    NETWORK ID          NAME                DRIVER              SCOPE 
    799f023c8549        bridge              bridge              local 
    d410cf433cde        host                host                local 
    f1515170d9e7        none                null                local 

 

  2) Docker network inspect "네트워크 이름"을 사용하는 모든 컨테이너의 IP 찾기
docker network inspect { bridege | host | none | ..... } -f "{{ json .Containers }}"

docker network inspect bridge -f "{{ json .Containers }}" | jq
{
  "10974a**":{
        "Name":"pgadmin4",
        "EndpointID":"**ee4526ea",
        "MacAddress":"02:42:ac:11:00:07",
        "IPv4Address":"172.17.0.7/16",
        "IPv6Address":""
  },
  "1e77d1b**":{
        "Name":"mynexus",
        "EndpointID":"**5bfc52871",
        "MacAddress":"02:42:ac:11:00:04",
        "IPv4Address":"172.17.0.4/16",
        "IPv6Address":""
  },
  "3e739395**":{
        "Name":"mypostgres",
        "EndpointID":"**dba06c4412",
        "MacAddress":"02:42:ac:11:00:05",
        "IPv4Address":"172.17.0.5/16",
        "IPv6Address":""
  },
  "42968c40b9**":{
        "Name":"mysqldb",
        "EndpointID":"3**ef3598bad",
        "MacAddress":"02:42:ac:11:00:02",
        "IPv4Address":"172.17.0.2/16",
        "IPv6Address":""
  },
  "7f9dabdc9096**":{
        "Name":"myjenkins","
        EndpointID":"**be1cd55f0c",
        "MacAddress":"02:42:ac:11:00:03",
        "IPv4Address":"172.17.0.3/16",
        "IPv6Address":""
  },
  "8a22fc716fd**":{
        "Name":"mysonarqube",
        "EndpointID":"**abbe0af086eb68e",
        "MacAddress":"02:42:ac:11:00:06",
        "IPv4Address":"172.17.0.6/16",
        "IPv6Address":""
  }
}

 

Comments