Detailed explanation on how to get the IP address of a docker container

Detailed explanation on how to get the IP address of a docker container

1. After entering the container

cat /etc/hosts

It will show the IP address of the container itself and the (- link) soft link.

2. Use 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. Consider writing a bash function in ~/.bashrc:

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

source ~/.bashrc and then:

$ docker_ip <container-ID>

172.17.0.6

4. To get all container names and their IP addresses just one command is needed.

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

If you use docker-compose the command 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)

The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM.

You may also be interested in:
  • Goodbye Docker: How to Transform to Containerd in 5 Minutes
  • Docker dynamically exposes ports to containers
  • How to enter and exit the Docker container
  • Docker learning: the specific use of Container containers
  • Detailed explanation of docker dynamically mapping running container ports
  • Docker removes abnormal container operations

<<:  How to write a Node.JS version of a game

>>:  MySQL 5.7.18 MSI Installation Graphics Tutorial

Recommend

Docker uses busybox to create a base image

The first line of a Docker image starts with an i...

JS cross-domain solution react configuration reverse proxy

Cross-domain solutions jsonp (simulate get) CORS ...

MySQL 5.7.21 installation and configuration tutorial

The simple installation configuration of mysql5.7...

MySQL slow query log configuration and usage tutorial

Preface MySQL slow query log is a function that w...

Why is UTF-8 not recommended in MySQL?

I recently encountered a bug where I was trying t...

Vue form input binding v-model

Table of contents 1.v-model 2. Binding properties...

Incomplete solution for using input type=text value=str

I encountered a very strange problem today. Look a...

Tutorial on Migrating Projects from MYSQL to MARIADB

Prepare the database (MySQL). If you already have...

How to view the database installation path in MySQL

We can view the installation path of mysql throug...

Implementation steps for enabling docker remote service link on cloud centos

Here we introduce the centos server with docker i...

How to dynamically add modules to Nginx

Written in front Often, after we install Nginx ba...

Detailed process of deploying Docker to WSL2 in IDEA

The local environment is Windows 10 + WSL2 (Ubunt...

Install Ubuntu 18 without USB drive under Windows 10 using EasyUEFI

1. Check BIOS First check which startup mode your...