Preface: Docker port mapping is often done by mapping the internal port of the container to the specified port of the host machine through -p during the Docker Run command. Generally speaking, the port corresponding to the container port is determined in advance to be mapped. However, in some cases, you have to temporarily map ports. For example, when running a MySQL container in Docker, the default port is not open. So is there any way to expose the specified port in the running container? Please read below---> Method 1: Change the Docker configuration file (risky) To achieve our goal, we need to modify the Docker configuration file. Generally speaking, we need to modify the following files: config.v2.json and hostconfig.json. The default path is First, shut down the Docker service through After completing the above configuration, restart the Docker service "Config": { "ExposedPorts": { // Add internal port 5432 mapping "5432/tcp": {}, "8080/tcp": {} },s ... }, "PortBindings":{ // Add internal port and external port 15432 "5432/tcp":[ { "HostIp":"", "HostPort":"15432" } ], "8080/tcp":[ { "HostIp":"", "HostPort":"28080" } ] }, Method 2: Iptables port forwardingThe principle of Docker's network port mapping is to achieve port forwarding through Iptables. Based on this principle, we can directly use iptables to forward the port to the target container IP. Port forwarding can be achieved by using the following command. This method relies on Iptables rules. In some scenarios, it may cause Iptables rule conflicts and affect the effective startup of the container. # Port mapping iptables -t nat -A DOCKER -p tcp --dport <container external port> -j DNAT --to-destination <container ip>:<container internal port> # Cancel the port mapping rule iptables -t nat -D DOCKER -p tcp -d 0/0 --dport <container external port> -j DNAT --to-destination <container ip>:<container internal port> This is the end of this article about how to dynamically modify container port mapping in Docker. For more information about how to modify container port mapping in Docker, please search for previous articles on 123WORDPRESS.COM or continue to browse the following related articles. I hope you will support 123WORDPRESS.COM in the future! You may also be interested in:
|
<<: Optimizing the slow query of MySQL aggregate statistics data
>>: JavaScript ES6 Module Detailed Explanation
Table of contents Semaphore Nginx hot deployment ...
1. Download the installation package Download add...
This article example shares the application code ...
Install Install ts command globally npm install -...
With the rise of mobile terminals such as iPad, p...
for loop Basic syntax format: for(initialize vari...
Preface In some cases, we only know the intranet ...
background This article mainly tests whether the ...
After installing Jenkins, the initial download of...
Table of contents Multiple conditional statements...
Linux: Linux version 3.10.0-123.9.3.el7.x86_64 Ng...
Table of contents What is a slot Understanding of...
Table of contents 1. Overview 1.1 Definition 1.2 ...
Linear-gradient background-image: linear-gradient...
This article shares the specific code of JavaScri...