A brief discussion on the preliminary practice of Docker container interconnection

A brief discussion on the preliminary practice of Docker container interconnection

1. Interconnection between Docker containers

Docker has now become a lightweight virtualization solution. On the same host machine, all containers can be interconnected through bridges. If you have experience with Docker before, you may be used to using --link to interconnect containers. As Docker gradually improves, it is strongly recommended that you use a bridge to interconnect containers.

2. Practice process

1. Create a network my-net:

[root@ChatDevOps ~]# docker network create my-net
71b42506de62797889372ea4a5270f905f79a19cf80e308119c02e529b89c94e
[root@ChatDevOps ~]# docker network ls
NETWORK ID NAME DRIVER SCOPE
3dec5cbb852e bridge bridge local
6dd6dcfc2f26 host host local
71b42506de62 my-net bridge local
4c142a02cd6b none null local

2. Specify the bridge network when creating the docker container:

[root@ChatDevOps docker]# docker create -it --name d1 --network my-net -p 8080:80 ubuntu:14.04
4776b65db566f370cad5da3a9354a12c7e4f9badab53647b7e30e1e8f343ae3d
[root@ChatDevOps docker]# docker start d1
d1

In this command, docker create can also be used as docker container create, and the two are equivalent. –name specifies the name of the container, –network specifies the network name of the container, the bridge mode defaults to bridge, and -p or –publish specifies the mapped port. If the network specified in this step has not been created in advance, the container will not be able to start normally. At this point, you can create a network for the container and start the container again.

3. You can also specify an already created network when running a docker container:

[root@ChatDevOps docker]# docker run -it --name d2 --network my-net --publish 8081:80 ubuntu:14.04 /bin/bash
root@07fd516911d0:/# ping d1
PING d1 (172.18.0.2) 56(84) bytes of data.
64 bytes from d1.my-net (172.18.0.2): icmp_seq=1 ttl=64 time=0.115 ms
root@4776b65db566:/# ping d2
PING d2 (172.18.0.3) 56(84) bytes of data.
64 bytes from d2.my-net (172.18.0.3): icmp_seq=1 ttl=64 time=0.062 ms

You can ping containers on the same bridge using the container name. You can also ping its IP directly.

Conclusion

1. After the docker installation is complete, the docker container has three networks, as follows:

[root@ChatDevOps ~]# docker network ls
NETWORK ID NAME DRIVER SCOPE
3dec5cbb852e bridge bridge local
6dd6dcfc2f26 host host local
4c142a02cd6b none null local

2. All container networks in the same network are interoperable.

3. The DNS configuration in the container's network configuration can be configured in the /etc/docker/daemon.json file on the host, referring to the official format:

{
 "bip": "192.168.1.5/24",
 "fixed-cidr": "192.168.1.5/25",
 "fixed-cidr-v6": "2001:db8::/64",
 "mtu": 1500,
 "default-gateway": "10.20.1.1",
 "default-gateway-v6": "2001:db8:abcd::89",
 "dns": ["10.20.1.2","10.20.1.3"]
}

You can configure it according to the actual situation.

The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM.

You may also be interested in:
  • Docker link realizes container interconnection
  • Detailed explanation of Docker port mapping and container interconnection
  • Docker learning notes: Weave realizes cross-host container interconnection
  • Detailed explanation of Docker container interconnection methods
  • Implementation of docker --link container interconnection

<<:  NestJs uses Mongoose to operate MongoDB

>>:  Encapsulation implementation of the data format returned by nestjs to the front end

Recommend

HTML input box optimization to improve user experience and ease of use

In order to improve user experience and ease of us...

Solution to 1045 error when navicat connects to mysql

When connecting to the local database, navicat fo...

Javascript front-end optimization code

Table of contents Optimization of if judgment 1. ...

MySQL column to row conversion, method of merging fields (must read)

Data Sheet: Column to row: using max(case when th...

Web Design Help: Web Font Size Data Reference

<br />The content is reproduced from the Int...

Discussion on the way to open website hyperlinks

A new window opens. Advantages: When the user cli...

Summary of common optimization operations of MySQL database (experience sharing)

Preface For a data-centric application, the quali...

A brief analysis of MySQL parallel replication

01 The concept of parallel replication In the mas...

Solution to leaving gaps between BootStrap grids

Table of contents [See an example]: [The original...

A brief discussion on MySQL large table optimization solution

background The amount of new data in the business...

Web Design Tutorial (7): Improving Web Design Efficiency

<br />Previous article: Web Design Tutorial ...

MySQL learning notes help document

View system help help contents mysql> help con...

Solve the problem of using swiper plug-in in vue

Since I used this plugin when writing a demo and ...

How to fix the width of table in ie8 and chrome

When the above settings are used in IE8 and Chrome...