In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)05/31 Report--
This article mainly introduces the relevant knowledge of "how to add port mapping after docker container startup". The editor shows you the operation process through an actual case. The operation method is simple, fast and practical. I hope this article "how to add port mapping after docker container startup" can help you solve the problem.
Conclusion: Port mapping can be added after the container is started, but it is not recommended to add it manually. It is best to use the functions provided by docker.
Steps
Two containers are created and ports are mapped, and the result is shown in the figure:
Suppose I start a container with an internal ip of 172.17.0.5 and start port 80 inside the container.
We don't need to worry about the forward rule chain. Docker has already written it for us. We only need to care about a few chains in nat.
View the prerouting chain in the nat table
As you can see from the above, iptables forwards all the data that meets the criteria to the docker chain.
View the docker chain in the nat table
Following the figure above, we add our own mapping rule to map the host port 8082 to port 80 of 172.17.0.5. The rules are as follows:
Iptables-t nat-a docker!-I docker0-p tcp-m tcp-- dport 8082-j dnat-- to-destination 172.17.0.5 docker 80
View the postrouting chain in the nat table
Following the rules in the above figure, the written rules are as follows:
Iptables-t nat-a postrouting-s 172.17.0.5 masquerade 32-d 172.17.0.5 tcp 32-p tcp-m tcp-- dport 80-j masquerade
View the docker chain in the filter table
Imitate the book writing rules as follows:
Iptables-t filter-a docker-d 172.17.0.5 tcp 32!-I docker0-o docker0-p tcp-m tcp-- dport 80-j accept
Result
Although the container with an ip of 172.17.0.5 does not enable port mapping, as shown in the following figure:
However, we can still access port 80 of 172.17.0.5 by accessing port 8082 of the host (192.168.78.238). The results are as follows:
One drawback of using this approach is that you cannot access the localhost:8082, which means that if you want to forward the localhost as well, you need to make additional configuration.
This is the end of the introduction to "how to add port mapping after docker container startup". Thank you for reading. If you want to know more about the industry, you can follow the industry information channel. The editor will update different knowledge points for you every day.
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.