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:
docker inspect [CONTAINER-ID] | grep IPAddress
Where [CONTAINER-ID] is the Docker container you want to view ID.
"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:
docker container ls
This command will list all running Docker containers.
docker container inspect [CONTAINER ID] | grep IPAddress
Where [CONTAINER ID] is the ID of the Docker container you want to view.
"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:
docker network inspect bridge
This command will list the details of the bridge network.
"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!