Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to realize the four port mappings of docker container

2025-03-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)05/31 Report--

In this article, the editor introduces in detail "how to achieve the four port mappings of the docker container". The content is detailed, the steps are clear, and the details are handled properly. I hope that this article "how to realize the four port mappings of the docker container" can help you solve your doubts.

Port mapping

Map the port of the container to a random or specific port of the host, and external users can access the container service.

Port mapping is originally forwarded by iptables address at the bottom of the container, outbound traffic is forwarded by SNAT source address, and incoming traffic is forwarded by DNAT destination address.

Four port mappings

Random port mapping: the port of the container is randomly mapped to a port of the host.

Specify port mapping: the port of the container is mapped to the designated port of the host.

Specify the random port mapping of the network card: the port of the container is mapped to the random port of the specified network card of the host.

Specify the port mapping of the network card: the port of the container is mapped to the specified port of the specified network card of the host.

Port mapping demonstrates random port mapping (- P)

Map the port of tomcat container 8080 to the random port of the host

[root@docker ~] # docker run-itd-P tomcat:latestfb8096ccc7866465f26ad41f98e4af53ce9a9ffa97f6036ed9314958c1cda457# View the mapping result Port 8080 of the container is mapped to port 32768 of the host [root@docker ~] # docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMESfb8096ccc786 tomcat:latest "catalina.sh run" 4 seconds ago Up 3 seconds 0.0.0.0 catalina.sh run 32768-> 8080/tcp nifty_shannon designated port Mapping (- p host port: container port)

Specify port 8080 of the tomcat container to be mapped to port 8000 of the host

[root@docker ~] # docker run-itd-p 8000 itd 8080 tomcat252ccaa33ebd731a56fa2d69da97183689fe59cc4059d2024ea39acc3c5f166f# View the mapping result Port 8080 of the container is mapped to port 8000 of the host [root@docker ~] # docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES252ccaa33ebd tomcat "catalina.sh run" 3 seconds ago Up 3 seconds 0.0.0.0 catalina.sh run 8000-> 8080/tcp trusting_archimedes designated network Card random port mapping (- p::)

Map port 8080 of the tomcat container to the random port of the host ens33 Nic

[root@docker ~] # docker run-itd-p 192.168.117.130 Fraser 8080 tomcat1cd63859b18da311b4cd0a7e10d70d06f0fa0e933fcef71eaef00696f6131379# View the mapping result Container port 8080 is mapped to host host port 192.168.117.130 catalina.sh run 32768 [root@docker ~] # docker psCONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES1cd63859b18d tomcat "catalina.sh run" 57 seconds ago Up 56 seconds 192.168.117.130 Suzhou 32768 -> 8080/tcp friendly_euclid specifies the Nic specified port mapping (- p host IP: host port: container port)

Map port 8080 of the tomcat container to port 8000 of the host ens33 Nic

[root@docker ~] # docker run-itd-p 192.168.117.130 tomcata19f247a387bfa5cb5d65fe6b23a98676a879672ef002259882c14a113a19b7c# 8000 itd 8080 tomcata19f247a387bfa5cb5d65fe6b23a98676a879672ef002259882c14a113a19b7c# view the mapping result Container port 8080 is mapped to host host port 192.168.117.130 catalina.sh run 8000 [root@docker] # docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMESa19f247a387b tomcat "catalina.sh run" 22 seconds ago Up 21 seconds 192.168.117.130000 -> 8080/tcp practical_wing read this. This article "how to implement four port mappings of docker containers" has been introduced. If you want to master the knowledge points of this article, you still need to practice and use it yourself. If you want to know more about related articles, please follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report