How to obtain the IP address of the Docker container (container) __docker

Source: Internet
Author: User
Tags docker ps
1. After entering the inside of the container
Cat/etc/hosts

will display its own and (–link) soft connection to the container IP 2. Using Commands

Docker Inspect--format ' {{. Networksettings.ipaddress} ' <container-ID>
Or
Docker Inspect <container id>
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}} ' $
}

SOURCE ~/.BASHRC and then:

$ docker_ip <container-ID>

172.17.0.6 4. Only one command is required to obtain all container names and their IP addresses.

Docker Inspect-f ' {{. Name}}-{{. Networksettings.ipaddress} ' $ (Docker Ps-aq)

If you use the Docker-compose command, you will be:

Docker Inspect-f ' {{. Name}}-{{range. networksettings.networks}}{{. Ipaddress}}{{end} ' $ (Docker Ps-aq)
5. Display all container IP addresses:
Docker Inspect--format= ' {{. Name}}-{{range. networksettings.networks}}{{. Ipaddress}}{{end} ' $ (Docker Ps-aq)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.