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

How to modify the created container port in docker

王林
Release: 2021-02-08 10:40:37
forward
3804 people have browsed it

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}
Copy after login

2. Modify hostconfig.json

vim hostconfig.json
Copy after login

Find the PortBindings node, the structure is as follows

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

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
Copy after login

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!

Related labels:
source:csdn.net
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template