Home>Article>Operation and Maintenance> How to modify docker container port

How to modify docker container port

王林
王林 forward
2020-07-03 17:14:09 5365browse

How to modify docker container port

The modification method is as follows:

(Recommended learning:docker tutorial)

1. Stop the container

2. Stop the docker service

systemctl stop docker

3. Modify the port in the hostconfig.json file of this container (if the port is also recorded in config.v2.json, you must also modify it)

cd /var/lib/docker/3b6ef264a040* #这里是CONTAINER ID
vi hostconfig.json

If there is no port mapping before, there should be a paragraph like this: "PortBindings":{}

Add a mapping like this: "PortBindings":{"3306/tcp":[{"HostIp":"" ,"HostPort":"3307"}]}

The first number is the container port, and the latter number is the host port. Modifying the existing port mapping is simpler, just change the port number.

4. Start the docker service

systemctl start docker

5. Start the container

The above is the detailed content of How to modify docker container port. 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
Previous article:How to understand docer? Next article:How to understand docer?