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

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

    Docker is written in Go and it uses Go syntax for query purposes too.

    To inspect the IP address of a particular container, you need to run the command (-f for "format"):

    docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' container_id_or_name
    

    For the container ID or name, you can run the command

    docker container ls
    

    which will list every running container.

提交回复
热议问题