Detailed explanation of Docker cross-host container communication overlay implementation process

Detailed explanation of Docker cross-host container communication overlay implementation process

There are also two servers:

Preparation:

Set the hostname of the container

consul: kv type storage database (key:value)
On docker01 and 02:
vim /etc/docker/daemon.json
{
 "hosts":["tcp://0.0.0.0:2376","unix:///var/run/docker.sock"], if this line is changed, you need to modify your docker configuration file "cluster-store": "consul://10.0.0.11:8500",
 "cluster-advertise": "10.0.0.11:2376" You can write your own IP address on the other machine.
vim /etc/docker/daemon.json
vim /usr/lib/systemd/system/docker.service
Change the line ExecStart=/usr/bin/dockerd --containerd=/run/containerd/containerd.sock to this line. You need to change systemctl daemon-reload on both machines.
systemctl restart docker

On docker01:

docker run -d -p 8500:8500 -h consul --name consul progrium/consul -server -bootstrap This command is done after setting the host name of the container [root@docker1 centos_zabbix]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
10.0.0.11:5000/kode v2 6914fda5fd44 4 hours ago 502MB
kode v2 6914fda5fd44 4 hours ago 502MB
10.0.0.11:5000/centos6.9_nginx_ssh v3 92b1087df3f5 13 hours ago 431MB
centos6.9_nginx_ssh v3 92b1087df3f5 13 hours ago 431MB
centos6.9_nginx_ssh v2 6307e23ee16d 13 hours ago 431MB
<none> <none> b94c822488f9 13 hours ago 431MB
centos6.9_nginx_ssh v1 f01eeebf918a 13 hours ago 431MB
<none> <none> 54167f1d659b 13 hours ago 431MB
<none> <none> 71474e616504 13 hours ago 430MB
centos6.9_ssh v2 03387f99f022 14 hours ago 307MB
<none> <none> 82d0e9ce844b 14 hours ago 195MB
kode v1 c0f486ac58fe 15 hours ago 536MB
progrium/consul latest 09ea64205e55 4 years ago 69.4MB Here is [root@docker1 centos_zabbix]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
1016753ee64d progrium/consul "/bin/start -server …" 4 minutes ago Exited (255) 3 minutes ago 53/tcp, 53/udp, 8300-8302/tcp, 8400/tcp, 8301-8302/udp, 0.0.0.0:8500->8500/tcp consul

Last visited on the page:

2) Create an overlay network

docker network create -d overlay --subnet 172.16.1.0/24 --gateway 172.16.1.254 ol1 This network segment cannot be the same as the host machine, and you can execute this command on any machine.

Check the container's network to see if overlay appears.

[root@docker1 shell]# docker network ls
NETWORK ID NAME DRIVER SCOPE
e480a4fe5f4b bridge bridge local
0a3cbfe2473f host host local
4e5ccdc657e1 macvlan_1 macvlan local
aab77f02a0b1 none null local
8ae111afded7 ol1 overlay global

3) Start container test

On one machine:
docker run -it --network ol1 --name test01 centos6.9_ssh:v2 /bin/bash
On another machine:
docker run -it --network ol1 --name test02 centos6.9_ssh:v2 /bin/bash
 
After that, you can connect between test01 and test02

After that, you can connect between test01 and test02

Real principle:

Each container has two network cards, eth0 for communication between containers, and eth1 for container access to the external network

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:
  • Cross-host communication between docker containers-overlay-based implementation method
  • Docker cleaning killer/Docker overlay file takes up too much disk space
  • Implementation of Docker cross-host network (overlay)
  • How to build a Docker overlay network
  • Docker overlay realizes container intercommunication across hosts

<<:  Vue2.x configures routing navigation guards to implement user login and exit

>>:  MySQL 8.0.19 supports locking an account after entering an incorrect password three times (example)

Recommend

How to track users with JS

Table of contents 1. Synchronous AJAX 2. Asynchro...

Is it necessary to create a separate index for the MySQL partition field column?

Preface Everyone knows that the partition field m...

How to check the hard disk size and mount the hard disk in Linux

There are two types of hard disks in Linux: mount...

Tutorial on installing and configuring MySql5.7 in Alibaba Cloud ECS centos6.8

The default MySQL version under the Alibaba Cloud...

MySQL trigger trigger add, delete, modify and query operation example

This article uses examples to describe the add, d...

Should nullable fields in MySQL be set to NULL or NOT NULL?

People who often use MySQL may encounter the foll...

HTML page header code is completely clear

All the following codes are between <head>.....

Explanation of nginx load balancing and reverse proxy

Table of contents Load Balancing Load balancing c...

5 Commands to Use the Calculator in Linux Command Line

Hello everyone, I am Liang Xu. When using Linux, ...

MySQL database master-slave configuration tutorial under Windows

The detailed process of configuring the MySQL dat...

Table shows the border code you want to display

Common properties of tables The basic attributes ...

A brief analysis of whether using iframe to call a page will cache the page

Recently, I have a project that requires using ifr...

Summary of Vue3 combined with TypeScript project development practice

Table of contents Overview 1. Compositon API 1. W...

How to dynamically modify container port mapping in Docker

Preface: Docker port mapping is often done by map...