Docker Network Basics

Source: Internet
Author: User
Tags docker ps

A large number of Internet application services include multiple service components , which often require multiple containers to interact with each other through network communication.

Docker currently provides a mapping container port to host host and container interconnect mechanism to provide network services for containers.

Port mappings implement access to containers:

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.

To access the container application externally:

When you run some network applications in a container, you can specify port mappings by using the-p or-p parameters when you want to allow external access to these applications. When the-p flag is used, Docker maps the ports in the 49000~49900 randomly to the open network ports inside the container.

Lowercase-p Specifies the port to be mapped, and only one container can be bound on a specified port. The supported formats are:

    • Ip:hostPort:containerPort
    • Ip::containerport
    • Hostport:containerport

Map all interface addresses:

Map Local 5000 ports to container 5000 ports using the Hostport:containerport format (example of a previously created private warehouse):

Docker run –d –p : Registry

The default is to bind all addresses on all interfaces. You can use the-p parameter multiple times to map multiple ports.

Map to the specified port at the specified address:

You can use the Ip:hostPort:containerPort format to specify that mappings use a specific address, such as Locakhost address 127.0.0.1.

Docker run –d –p 127.0.0.1: Registry

Any port mapped to the specified address:

You can use the Ip::containerport format to help top-of-localhost any port to port 5000 of the container, and the local host automatically assigns a port:

Docker run –d –p 127.0.0.1:: Registry

You can use UDP tokens to specify UDP ports:

Docker run –d –p 127.0.0.1:registry<:/UDP /c14>

To view the port mapping configuration:

You can use the Docker Port command to view the currently mapped port configuration or to view the address of the binding:

Docker Port Registry

0.0.0.0/tcp : Docker Port Registry 0.0.0.0:

The container has its own internal network and IP address (all variable values can be obtained using Docker inspect + ID).

Container interconnect for inter-container communication:

The container's connection (linking) system is another way to interact with the application in the container, in addition to the port mapping. He creates a tunnel between the source and the receiving container, accepting that the container can see the information specified by the source container.

Container interconnection:

Use the –link parameter to allow safe interaction between containers.

such as creating a database container:

Docker run -name dbserver mysql

Let's create a container and connect the container to the DBServer container:

Docker run –d -name likeweb -link dbserver:dbserver ubuntu

Because the container to be connected does not start, so after the completion of the container will be an error, this is just a demonstration –link, please ignore.

The format of the –link parameter is –link Name:alias, where name is the name of the container to be linked, and alias is the alias of the connection.

You can view the connection situation with the Docker PS command.

This creates a secure tunnel between Docker two containers without the need to open the external ports, avoiding the database ports on the external network.

Docker exposes connection information to a container in two ways:

    • Environment variables
    • Update/etc/hosts file

You can use the ENV command to view the container's environment variables.

Docker now uses the Linux system's own network system to support network services, which can provide stable support with existing proven technology, while enabling fast high-performance forwarding.

Turn from: Dream Continuation code

Docker Network Basics

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.