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

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

    The --format option of inspect comes to the rescue.

    Modern Docker client syntax is:

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

    Old Docker client syntax is:

    docker inspect --format '{{ .NetworkSettings.IPAddress }}' container_name_or_id
    

    These commands will return the Docker container's IP address.

    As mentioned in the comments: if you are on Windows, use double quotes " instead of single quotes ' around the curly braces.

提交回复
热议问题