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

Docker link realizes container interconnection

Table of contents 1.1. Network access between con...

Use auto.js to realize the automatic daily check-in function

Use auto.js to automate daily check-in Due to the...

js implements a simple countdown

This article example shares the specific code of ...

A brief discussion on which fields in Mysql are suitable for indexing

Table of contents 1 The common rules for creating...

Vue Element UI custom description list component

This article example shares the specific code of ...

vue3.0+echarts realizes three-dimensional column chart

Preface: Vue3.0 implements echarts three-dimensio...

Avoiding Problems Caused by Closures in JavaScript

About let to avoid problems caused by closure Use...

MySQL case when group by example

A mysql-like php switch case statement. select xx...

How to use indexes to optimize MySQL ORDER BY statements

Create table & create index create table tbl1...

Detailed steps for QT to connect to MYSQL database

The first step is to add the corresponding databa...

10 excellent Web UI libraries/frameworks

1. IT Mill Toolkit IT Mill Toolkit is an open sou...

Detailed explanation of MySQL Explain

In daily work, we sometimes run slow queries to r...

Compatibility with the inline-block property

<br />A year ago, there were no articles abo...

How to start jar package and run it in the background in Linux

The Linux command to run the jar package is as fo...