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

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

    To get all container names and their IP addresses in just one single command.

    docker inspect -f '{{.Name}} - {{.NetworkSettings.IPAddress }}' $(docker ps -aq)
    

    If you are using docker-compose the command will be this:

    docker inspect -f '{{.Name}} - {{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' $(docker ps -aq)
    

    The output will be:

    /containerA - 172.17.0.4
    /containerB - 172.17.0.3
    /containerC - 172.17.0.2
    

提交回复
热议问题