Home > Operation and Maintenance > Docker > How to change docker container port

How to change docker container port

王林
Release: 2020-09-14 11:49:19
forward
6452 people have browsed it

How to change docker container port

We know that docker run can specify port mapping, but once the container is generated, there is no command that can be modified directly. Usually the indirect method is to save the image, create a new container, and specify the new port mapping when creating it.

(Recommended tutorial: docker tutorial)

So is there any way to directly modify the existing container without saving the image?

The specific method is as follows:

1) Stop the container

2) Stop the docker service (systemctl stop docker)

3) Modify the hostconfig of this container. The port in the json file (someone mentioned in the original post that if the port is also recorded in config.v2.json, it must also be modified)

cd /var/lib/docker/3b6ef264a040* #这里是CONTAINER ID
vi hostconfig.json
#如果之前没有端口映射, 应该有这样的一段:
"PortBindings":{}
#增加一个映射, 这样写:
"PortBindings":{"3306/tcp":[{"HostIp":"","HostPort":"3307"}]}
#前一个数字是容器端口, 后一个是宿主机端口.
#而修改现有端口映射更简单, 把端口号改掉就行.
Copy after login

4) Start the docker service (systemctl start docker)

5) Start container

The above is the detailed content of How to change docker container port. 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