CodePudding user response:
1, get the container IPTo replace container_name with containers of the actual environment
Docker inspect ` container_name ` | grep IPAddress
2, iptables forwarding port
The container port 8000 is mapped to the docker host port 8001
The iptables -t NAT - A DOCKER -p TCP -- dport 8001 - j DNAT - to - destination 172.17.0.19:8000
CodePudding user response:
# # to check the id is container hash_of_the_container numericalDocker inspect the container name
# # modified hostconfig. Json
Vim/var/lib/docker/containers/[hash_of_the_container]/hostconfig json
In hostconfig. There are "PortBindings" in json: {} the configuration items, you can change to "PortBindings" : {" 80/TCP ": [{" HostIp" : ""," HostPort ":" 8080 "}]}
# # modified config. V2. Json
Vim/var/lib/docker/containers/[hash_of_the_container]/config. The v2. Json
In the config. V2. Add a json configuration items "ExposedPorts" : {" 80/TCP ": {}}, add the configuration items to the" Tty ":
in front of the true,# # the last restart docker daemon service docker restart
# # to check the configuration items have modified success
Docker inspect container name
https://www.cnblogs.com/wangkai333/p/11794521.html
CodePudding user response:
Iptables approach is possible, but no iptables alpine as the default, in addition, the container system of IP is not fixed, IP changed after server restart,CodePudding user response:
Docker should give a command dynamic configuration port mapping,