Docker Port mapping:
Recent time, the Docker port mapping data to be sorted, in order to follow-up project application, we can also refer to the next.
# Find IP addresses of container with ID <container_id> get IP $ sudo via container ID inspect <container_id> | grep IPAddress | Cut-d ' "'-F 4
In any case, the IP is based on the local system and the port of the container is not reachable by the local host. In addition, except for ports that can only be accessed locally, another problem with the container is that these IPs will change each time the container starts.
Docker solves these two problems with the container and provides a simple and reliable way to access the container's internal services. Docker interfaces that bind host systems through ports, allowing non-local clients to access services running inside the container. In order to facilitate the communication between containers, Docker provides this connection mechanism.
5.1 Automatic Map port
-p use to specify the--expose option to specify the ports that need to be serviced externally
$ sudo docker run-t-P--expose--name Server ubuntu:14.04
Using Docker run-p automatically binds all container ports that provide services externally, the mapped ports will automatically be selected from unused port pools (49000..49900), and you can pass Docker PS, Docker inspect > or Docker Port <container_id> <port> to determine specific binding information.
5.2 Bound port to specified interface
Basic syntax
$ sudo docker run-p [([
The default does not specify the binding IP to listen for all network interfaces.
Binding TCP Ports
# Bind TCP Port 8080 of the container to TCP port of 127.0.0.1 of the host machine. $ sudo docker run-p 127.0.0.1:80:8080 <image> <cmd> # Bind TCP port 8080 of container to a dynamically al Located TCP port on 127.0.0.1 of the host machine. $ sudo docker run-p 127.0.0.1::8080 <image> <cmd> # Bind TCP port 8080 of the container to TCP port Available interfaces of the host machine. $ sudo docker run-p 80:8080 <image> <cmd> # Bind TCP port 8080 of the container to a dynamically allocated TC P port on all available interfaces $ sudo docker run-p 8080 <image> <cmd>
Binding UDP Ports
# Bind UDP Port 5353 of the container to UDP port on 127.0.0.1 of the host machine. $ sudo docker run-p 127.0.0.1:53:5353/udp <image> <cmd>
Thank you for reading, I hope to help you, thank you for your support for this site!