Docker dynamically exposes ports to containers

Docker dynamically exposes ports to containers

View the IP address of the Container

docker inspect <container name or id>| grep IPAddress

View the mapped port of the Container

docker port <container name or id>
eg.
docker port d8dac7399647
docker port hfq-jedi-zxf-eden

Use iptables to view container mapping

iptables -t nat -nvL

iptables -t nat -nvL --line-number

Example of adding a new port mapping

##Map host port 31101 to container port 6379

iptables -t nat -A PREROUTING -p tcp -m tcp --dport 31101 -j DNAT --to-destination 192.168.42.2:6379

Save iptables rules

iptables-save

illustrate

192.168.42.2 is the result of docker inspect <container name or id>| grep IPAddress

After the port mapping is completed, the result cannot be queried through docker port d8dac7399647

Can be

iptables -t nat -nvL | grep 192.168.42.2

Query mapping relationship

Additional knowledge: Mechanisms in Docker container communication and port exposure issues

The link method has always been used for communication between Docker containers. This limits the order in which each container is started, which always feels inflexible. Therefore, this time we explored accessing containers directly through the LAN allocated by the Docker's own network card.

Docker port exposure means forwarding the port service of the container itself to the exposed port through the forwarding of the docker0 network card, for example, executing:

docker run -dit -p 8080:12345 --name=container_name image_name

When accessing using the 172.17.0.x local area network assigned by the docker0 network card, use port 12345. When using 192.168.1.x or other local public IP to access, you need to use 8080 to access

Time is limited, so I won't analyze it in detail for now. I'll analyze it with pictures when I have time.

The above article about Docker dynamically exposing ports to containers is all I have to share with you. I hope it can give you a reference. I also hope that you will support 123WORDPRESS.COM.

You may also be interested in:
  • Talk about the issue of replacing docker (shim) with containerd in kubernetes1.20
  • How to keep running after exiting Docker container
  • Docker removes abnormal container operations
  • Goodbye Docker: How to Transform to Containerd in 5 Minutes
  • Delete the image operation of none in docker images
  • Implementation of local migration of docker images
  • Solve the problem of docker images disappearing
  • Docker image cannot be deleted Error: No such image: xxxxxx solution
  • How to delete an image in Docker
  • Naming containers and images in Docker

<<:  Detailed explanation of Vue mixin usage and option merging

>>:  Change the MySQL database engine to InnoDB

Recommend

Detailed explanation of the process of zabbix monitoring sqlserver

Let's take a look at zabbix monitoring sqlser...

How to view image information in Docker

In this article, we will need to learn how to vie...

A complete guide to CSS style attributes css() and width() in jQuery

Table of contents 1. Basic use of css(): 1.1 Get ...

A few steps to easily build a Windows SSH server

The SSH mentioned here is called Security Shell. ...

Detailed explanation of how to upgrade software package versions under Linux

In the Linux environment, you want to check wheth...

Detailed explanation of CSS3 text shadow text-shadow property

Text shadow text-shadow property effects: 1. Lowe...

Image scrolling effect made with CSS3

Achieve resultsImplementation Code html <base ...

Let's talk about MySQL joint query in detail

Table of contents Union query 1. Query the ID and...

How to enable or disable SSH for a specific user or user group in Linux

Due to your company standards, you may only allow...

Should the Like function use MySQL or Redis?

Table of contents 1. Common mistakes made by begi...

vue.js downloads pictures according to picture url

Recently, when I was working on a front-end vue.j...

Summary of MySQL foreign key constraints and table relationships

Table of contents Foreign Key How to determine ta...

Detailed explanation of the new array methods in JavaScript es6

Table of contents 1. forEach() 2. arr.filter() 3....

How to use MySQL covering index and table return

Two major categories of indexes Storage engine us...