How to get a Docker container's IP address from the host?
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 want to roll my own code deployment and container configuration scripts.
docker inspect <container id> | grep "IPAddress"
The --format
option of inspect comes to the rescue.
Modern Docker client syntax:
docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' container_name_or_id
Old Docker client syntax:
docker inspect --format '{{ .NetworkSettings.IPAddress }}' container_name_or_id
Which will return just the IP address.
You can use docker inspect <container id>
Example:
CID=$(docker run -d -p 4321 base nc -lk 4321);
docker inspect $CID
链接地址: http://www.djcxy.com/p/3000.html
上一篇: 如何删除旧的Docker容器