Docker port mapping for network access
First of all, if you see what you do not understand, welcome to the groove ...
I will reply in a timely manner on the day or the next day, and improve ~ ~
Docker ran the container and found no IP, no port, then how to access the container.
Let me introduce the following Docker through port mapping to achieve network access
One, external access to the container application
When you start the container, if you do not specify a corresponding parameter, the network applications and services within the container cannot be accessed through the network outside the container.
When running some network applications in the container, you can specify the port mappings through the-p or-p parameters for external access to these applications.
First of all, p and P-P can specify the port to be mapped, and only one container can be bound on a specified port-p It randomly maps a port to an open network port inside the container (the range is unknown, it seems to be tens of thousands)
Just make a statement, my side.
Client IP address is 192.168.0.225
Registry IP Address is 192.168.0.216:5000
Docker run-d-it--name nginx-p 192.168.0.216:5000/nginx
Docker ps-a #查看容器是否在运行
docker logs Nginx #查看n Log of the Ginx container
The supported formats for port mappings are:
Ip:hostport:containerport #指定ip, specify host port, specify container port
ip::containerport #指定ip, unspecified host port, specify container port
Hostport:container #未指定ip Port, specify host port, specify container port
Second, map all interface IP
The following command looks at the 0.0.0.0 Monitor 5000 port
Docker run-d-it-p 5000:5000--name Registry 192.168.0.216:5000/registry
Docker Ps-a | g Rep
many times use the-p flag to bind multiple ports
Docker run-d-it-p 800:80-p 8088:8080--name Tomcat 192.168.0.216:5000/tomcat do
Cker Ps-a | Egrep "(80|8080)"
Third, the specified port mapped to the specified address
Map the container's port to 192.168.0.225:800
Docker run-d-it-p 192.168.0.225:800:80--name web_server 192.168.0.216:5000/ Nginx
Curl 192.168.0.225:800 #验证是否可以访问默认首页
Iv. UDP ports mapped to the specified address
Here and not say can not access, just a way of mapping. No offense, everyone.
Docker run-d-it-p 192.168.0.225:300:3000/udp--name unknown 192.168.0.216:5000/nginx
Netstat-anpu | grep UDP
UDP 0 0 192.168.0.225:300 0.0.0.0:* 24588/docker-proxy
V. View MAP Port Configuration
through Docker port container_id you can see which ports and protocols the container mapped [root@docker ~] #docker Port Tomcat 8080/tcp 192.168.0.225:32769 [Root@docker ~] #docker port unknown 3000/udp, 192.168.0.225:300