Docker port Mapping Detailed description _docker

Source: Internet
Author: User
Tags get ip docker ps docker run

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!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.