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

后端 未结 30 2819
小鲜肉
小鲜肉 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

    As of Docker version 1.10.3, build 20f81dd

    Unless you told Docker otherwise, Docker always launches your containers in the bridge network. So you can try this command below:

    docker network inspect bridge
    

    Which should then return a Containers section which will display the IP address for that running container.

    [
        {
            "Name": "bridge",
            "Id": "40561e7d29a08b2eb81fe7b02736f44da6c0daae54ca3486f75bfa81c83507a0",
            "Scope": "local",
            "Driver": "bridge",
            "IPAM": {
                "Driver": "default",
                "Options": null,
                "Config": [
                    {
                        "Subnet": "172.17.0.0/16"
                    }
                ]
            },
            "Containers": {
                "025d191991083e21761eb5a56729f61d7c5612a520269e548d0136e084ecd32a": {
                    "Name": "drunk_leavitt",
                    "EndpointID": "9f6f630a1743bd9184f30b37795590f13d87299fe39c8969294c8a353a8c97b3",
                    "IPv4Address": "172.17.0.2/16",
                    "IPv6Address": ""
                }
            },
            "Options": {
                "com.docker.network.bridge.default_bridge": "true",
                "com.docker.network.bridge.enable_icc": "true",
                "com.docker.network.bridge.enable_ip_masquerade": "true",
                "com.docker.network.bridge.host_binding_ipv4": "0.0.0.0",
                "com.docker.network.bridge.name": "docker0",
                "com.docker.network.driver.mtu": "1500"
            }
        }
    ]
    

提交回复
热议问题