Home >Operation and Maintenance >Docker >How to modify the created container port in docker

How to modify the created container port in docker

王林
王林forward
2021-02-08 10:40:373790browse

How to modify the created container port in docker

We can modify the created container port in the following two ways.

(1) Submit the container as a mirror and re-run to modify the container configuration file

(2) Submit the container as a mirror and re-run

Modify the container configuration file

Docker needs to be closed before modification, otherwise after the mirror is restarted, the configuration file will be restored and the modification will fail.

1. Enter the container configuration directory

cd /var/lib/docker/containers/{container_id}

2. Modify hostconfig.json

vim hostconfig.json

Find the PortBindings node, the structure is as follows

{
    "PortBindings": {
    	"80/tcp": [
	        {
				"HostIp": "",
				"HostPort": "81"
			}
    	]
    }
}

The meaning of this node is to map the server's port 81 to the container's port 80

3. config.v2.json file

The ExposedPorts inside also has port information, I don’t know what its use is at the moment

Reference

https://stackoverflow.com/questions/19335444/how-do-i-assign-a-port-mapping-to-an-existing-docker-container

Related recommendations:docker introductory tutorial

The above is the detailed content of How to modify the created container port in docker. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:csdn.net. If there is any infringement, please contact admin@php.cn delete