Docker container network communication - external access to internal

"Access to the Intranet from the Outside World:"

 

Principle: Port Mapping

 

 

 

1. Run a container and open the container port 80 mapping

docker run -d -p 80 httpd

2. Check and find that 80 of the physical machine is not turned on

netstat -napt | grep 80

 

3. Check docker ps and find that the port 80 opened inside the container is just mapped to a random port on the physical machine.

docker ps

 

 

4. By accessing the IP address + random port of the physical machine, you can access the default home page file of the httpd container.

elinks http://ip: random port outside the container

Such as:

elinks http://192.168.6.110:32768

 

5. You can also specify the port of the physical machine for mapping

docker run -d -p 8080:80 httpd

elinks http://192.168.6.110:8080

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324884141&siteId=291194637