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

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

    To extend ko-dos' answer, here's an alias to list all container names and their IP addresses:

    alias docker-ips='docker ps | tail -n +2 | while read -a a; do name=${a[$((${#a[@]}-1))]}; echo -ne "$name\t"; docker inspect $name | grep IPAddress | cut -d \" -f 4; done'
    

提交回复
热议问题