Home  >  Article  >  Operation and Maintenance  >  How to check docker virtual machine ip

How to check docker virtual machine ip

PHPz
PHPzOriginal
2023-04-19 09:18:465642browse

In the Docker container, each container has its own IP address, and the Docker virtual machine IP address can be viewed in different ways. In this article, we will cover how to use different methods to view the Docker virtual machine IP address.

Method 1: Use docker inspect

In a Docker container, you can use the docker inspect command to view the detailed information of the container, including the IP address. Here are the steps to view the container IP address:

  1. Open a terminal window and enter the following command:
docker inspect [CONTAINER-ID] | grep IPAddress

Where [CONTAINER-ID] is the Docker container you want to view ID.

  1. After pressing the Enter key, the details of the container, including the IP address, will be returned. For example:
"SecondaryIPAddresses": null,
            "IPAddress": "172.17.0.3",
                    "IPAddress": "172.17.0.3",

In this example, the container’s IP address is 172.17.0.3.

Method 2: Use docker container ls

Another way to check the IP address of the Docker virtual machine is to use the docker container ls command. Here are the steps to view the IP address of a container:

  1. Open a terminal window and enter the following command:
docker container ls

This command will list all running Docker containers.

  1. Find the container whose IP address you want to view and record its CONTAINER ID.
  2. Enter the following command to view the IP address of the container:
docker container inspect [CONTAINER ID] | grep IPAddress

Where [CONTAINER ID] is the ID of the Docker container you want to view.

  1. After pressing the Enter key, the details of the container, including the IP address, will be returned. For example:
"SecondaryIPAddresses": null,
            "IPAddress": "172.17.0.3",
                    "IPAddress": "172.17.0.3",

In this example, the container’s IP address is 172.17.0.3.

Method 3: Use docker network inspect

Docker also provides another way to view the IP address of the Docker virtual machine, which is to use the docker network inspect command. Here are the steps to view the container IP address:

  1. Open a terminal window and enter the following command:
docker network inspect bridge

This command will list the details of the bridge network.

  1. After pressing the Enter key, the details of the bridge network will be returned, including details of all containers associated with that network.
  2. In the returned information, find the container whose IP address you want to view and record its ID.
  3. Find the details of the container, including its IP address. For example:
"Containers": {
                "1001a36f15529c63bdf21d1fc2f9c653496f34d11ce0b87d58dea2c2ced78312": {
                    "Name": "my-container",
                    "EndpointID": "f763d9855d743f5227cc5703303a71b2c2834bf0e4ad333cd0e5521dc8d866c1",
                    "MacAddress": "02:42:ac:11:00:03",
                    "IPv4Address": "172.17.0.3/16",
                    "IPv6Address": ""
                }
            },

In this example, the container’s IP address is 172.17.0.3.

Summary

Each container in a Docker container has its own IP address. You can use different methods to view the Docker virtual machine IP address, including using docker inspect, docker container ls and docker network inspect command. These methods make it easy to view a container’s IP address and other details to better manage and maintain Docker containers.

The above is the detailed content of How to check docker virtual machine ip. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn