This article is a mirror article of machine translation, please click here to jump to the original article.

View: 8495|Reply: 0

Modify the method of port mapping for docker containers

[Copy link]
Posted on 10/12/2018 11:06:10 AM | | | |
Everyone knows that docker run can specify port mappings, but once a container is generated, there is no command that can be directly modified. Usually indirectly, save the image and create a new container, specifying the new port map at the time of creation.

Is there a way to modify the existing container without saving the image? Yes. I found the answer on stackoverflow, the original post is as follows

https://stackoverflow.com/questi ... ng-docker-container

I'm mapping the 8080 port of the rap2-delos container to the 80 of the host machinePort above, as shown below:



Right nowI now want to map the 8080 port of the rap2-delos container to the 8080 port of the host machineabove.

The tutorial is as follows

--Stop container

--Run docker inspect [CONTAINER ID] | grep id command

--Run the cd /var/lib/docker/containers command to find the directory with the same ID, as shown in the figure below



Stop docker engine service, systemctl stop docker

Modify the hostconfig.json configuration file

example

vi hostconfig.json
If there was no port mapping before, there should be a paragraph like this:
"PortBindings":{}
Add a mapping that reads:
"PortBindings":{"3306/tcp":[{"HostIp":"","HostPort":"3307"}]}
The first number is the container port, and the last one is the host port.


After modifying and saving the configuration, finally start the docker service

systemctl start docker

Done







Previous:MySQL CPU 100% high solution
Next:vs code TSLint common error solution
Disclaimer:
All software, programming materials or articles published by Code Farmer Network are only for learning and research purposes; The above content shall not be used for commercial or illegal purposes, otherwise, users shall bear all consequences. The information on this site comes from the Internet, and copyright disputes have nothing to do with this site. You must completely delete the above content from your computer within 24 hours of downloading. If you like the program, please support genuine software, purchase registration, and get better genuine services. If there is any infringement, please contact us by email.

Mail To:help@itsvse.com