Get the App
SLTechnology News&Howtos  ›  Servers  › 

How to get the ip address of docker container (container)

Shulou Source: shulou.com Published: 2022-06-02 00:11:29 09月29日 Update

This article is about how to get the ip address of the docker container (container). The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.

1. After entering into the container,

Cat / etc/hosts

The container IP that displays itself and (- link) the soft connection

two。 Use the command

Docker inspect-- format'{{.NetworkSettings.IPAddress}}'

Or

Docker inspect

Or

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

3. You can consider writing a bash function in ~ / .bashrc:

Function docker_ip () {sudo docker inspect-- format'{{.NetworkSettings.IPAddress}}'$1}

Source ~ / .bashrc and then:

$docker_ip

172.17.0.6

4. It takes only one command to get all the container names and their IP addresses.

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

If you use the docker-compose command, you will:

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

5. Show all container IP addresses:

Docker inspect-- format=' {{.Name}}-{{range .NetworkSettings.Networks}} {{.IPAddress}} {{end}}'$(docker ps-aq) Thank you for reading! This is the end of the article on "how to get the ip address of the docker container (container)". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it for more people to see!

Tags: Container address command content more article good practical function just name article see knowledge reference help related Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Technology Linux Redmi Microsoft OPPO Reno