How to access containers in the external world? -Play Docker container technology every 5 minutes (37)

Source: Internet
Author: User

How to access containers in the external world? -Play Docker container technology every 5 minutes (37)

In the previous section, we learned how to access the external network of containers. Today we will discuss another direction: how to access the container from the external network?


The answer is:Port ing.

Docker maps the port that the container provides external services to a port of the host. The Internet accesses the container through this port. When the container is started, use the-p parameter to map the Port:

After the container is started, you can view the host ing port through docker ps or docker port. In the preceding example, port 80 of the httpd container is mapped to host 32773, so that you can access the web Service of the container through

In addition to ing dynamic ports, you can also specify a specific port mapped to the host in-p. For example, you can map port 80 to port 8080 of the host:

For each mapped port, the host starts a docker-proxy process to process the traffic to the container:

Take 0.0.0.0: 32773-> 80/tcp as an example to analyze the entire process:

  1. Docker-proxy listens to port 32773 of the host.

  2. When curl accesses 10.0.2.15: 32773, docker-proxy forwards it to container 172.17.0.2: 80.

  3. The httpd container responds to the request and returns the result.

Summary of this Chapter

In this chapter, we first learned three types of Docker networks: none, host, and bridge, and discussed their different use cases. Then we practiced creating a custom network; finally, we discuss in detail how to implement communication between containers and external networks.

This chapter focuses on the container network in a single host. Cross-host network communication will be discussed in detail in later sections. In the next section, learn about Docker storage.

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.