Docker Quick Start series (5): basic network configuration and communication during storage, docker Quick Start

Source: Internet
Author: User
Tags custom name

Docker Quick Start series (5): basic network configuration and communication during storage, docker Quick Start
Introduction

Two major functional modules that are essential for a web service to run: business processing, data services, and large web services require more components, which usually requires multiple containers, however, we also need to allow network communication between these containers and cooperate with each other.
Currently, Dokcer only supports communication between host machines and containers.

Port ing between host and container

When you start a container, if no corresponding parameter is specified, you cannot access network applications and services in the container outside the container.
To allow external access to some network applications in the container, you can use the-p or-p parameters to define port ing. When the-p Flag is used, Docker will map a 49000 ~ Port 49900 to the network port developed inside the container:

# I don't know why the container does not map ports after I-P here, but the official example can be used.

The second method is to create a port ing relationship for the container:

Map multiple mappings at the same time:

Port ing of the specified address:

Map any port of the specified address:

Port ing between containers and containers

In addition to port ing, the container connection system can interact with applications in the container. It creates a tunnel between the source and the receiving container, and the receiving container can see the information specified by the container.

Custom container name

The Connection System is executed based on the container name. Therefore, you must first customize a memorable container name.
Although a name is assigned by default when a container is created, the custom naming container has two advantages:
1. The custom name is easy to remember. For example, for a web application container, We can name it web
2. When connecting to other containers, it can be used as a useful reference, such as connecting web containers to db containers.
You can use the-name tag to customize the container name:

docker run -d -P -name web ubuntu:nodejs

You can also useDocker inspectTo view the container Name:

docker inspect -f "{{.Name}}" CONTAINER_ID

The-link parameter allows secure interaction between containers:

docker run -d -P --name web --link db:db ubuntu:nodejs

-The format of the link parameter is-link name: alias, where name is the name of the container to be connected, and alias is the alias of the connection.

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.