How to get a Docker container's IP address from the host

后端 未结 30 2395
小鲜肉
小鲜肉 2020-11-22 08:45

Is there a command I can run to get the container\'s IP address right from the host after a new container is created?

Basically, once Docker creates the container, I

30条回答
  •  醉酒成梦
    2020-11-22 09:21

    For those who came from Google to find a solution for command execution from the terminal (not by a script), "jid", which is an interactive JSON drill-down utility with autocomplete and suggestion, lets you do the same thing with less typing.

    docker inspect $CID | jid
    

    Type Tab .Net Tab and you'll see something like:

    [Filter]> .[0].NetworkSettings
    {
      "Bridge": "",
      "EndpointID": "b69eb8bd4f11d8b172c82f21ab2e501fe532e4997fc007ed1a997750396355d5",
      "Gateway": "172.17.0.1",
      "GlobalIPv6Address": "",
      "GlobalIPv6PrefixLen": 0,
      "HairpinMode": false,
      "IPAddress": "172.17.0.2",
      "IPPrefixLen": 16,
      "IPv6Gateway": "",
      "LinkLocalIPv6Address": "",
      "LinkLocalIPv6PrefixLen": 0,
      "MacAddress": "02:42:ac:11:00:02",
      "Networks": {
        "bridge": {
          "Aliases": null,
          "EndpointID": "b69eb8bd4f11d8b172c82f21ab2e501fe532e4997fc007ed1a997750396355d5",
          "Gateway": "172.17.0.1",
          "GlobalIPv6Address": "",
    

    Type .IPA Tab and you'll see something like:

    [Filter]> .[0].NetworkSettings.IPAddress
    "172.17.0.2"
    

提交回复
热议问题