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

Use SQL statement to determine whether the record already exists before insert

Table of contents Determine whether a record alre...

How is a SQL statement executed in MySQL?

Table of contents 1. Analysis of MySQL architectu...

SQL uses ROW_NUMBER() OVER function to generate sequence number

Syntax: ROW_NUMBER() OVER(PARTITION BY COLUMN ORD...

Detailed explanation of Mybatis special character processing

Preface: Mybatis special character processing, pr...

Introduction to MySQL isolation level, lock and MVCC

This article aims to clarify the relationship bet...

Mysql example of splitting into multiple rows and columns by specific symbols

Some fault code tables use the following design p...

CentOS6.9+Mysql5.7.18 source code installation detailed tutorial

CentOS6.9+Mysql5.7.18 source code installation, t...

Vue custom directive details

Table of contents 1. Background 2. Local custom i...

MySql import CSV file or tab-delimited file

Sometimes we need to import some data from anothe...

How to install and configure ftp server in CentOS8.0

After the release of CentOS8.0-1905, we tried to ...

Summary of basic knowledge points of Linux group

1. Basic Introduction of Linux Group In Linux, ev...

Python MySQL database table modification and query

Python connects to MySQL to modify and query data...

CSS3 custom scroll bar style::webkit-scrollbar sample code detailed explanation

The default scroll bar style in Windows is ugly, ...