Get the App
SLTechnology News&Howtos  ›  Servers  › 

How to realize docker Cross-host Communication

Shulou Source: shulou.com Published: 2022-05-31 20:22:55 09月28日 Update

This article mainly explains "how to achieve docker cross-host communication". The content of the article is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "how to achieve docker cross-host communication".

# A Host 192.168.100.12

Create a subnet in host A with a range of 10.52.100.2-> 10.52.100.254

Docker network create-subnet=10.52.100.0/24 snake120

Run a centos7 container as a client

Docker run-name centos-dit-network snake120-ip 10.52.100.2 uhub.service.ucloud.cn/pub021/centos:7.4.1708

Add a route to the host where the destination address is located,-net destination IP, gw gateway IP, default eth0 Nic

Route add-net 10.52.121.0 netmask 255.255.255.0 gw 192.168.100.121

Server-side open forwarding rules for communication from host B to host A.

Iptables-A FORWARD-j ACCEPT

# B host 192.168.100.12

Create a subnet in host B with a range of 10.52.121.2-> 10.52.121.254

Docker network create-subnet=10.52.121.0/24 snake121

Run a target service

Docker run-name nginx-dit-network snake121-ip 10.52.121.10 uhub.service.ucloud.cn/pub021/nginx:1.17.10

Server-side open forwarding rules for communication from host A to host B.

Iptables-A FORWARD-j ACCEPT

Add a route to the host where the destination address is located,-net target IP, gw gateway IP, default eth0 network card. This is to initiate communication from host B to host An actively and communicate with each other.

Route add-net 10.52.120.0 netmask 255.255.255.0 gw 192.168.100.120 Thank you for your reading, the above is the content of "how to achieve docker cross-host communication". After the study of this article, I believe you have a deeper understanding of how to achieve docker cross-host communication, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

Tags: Host communication target learning service content address host host location pointing gateway network card scope rules routing creation subnet open operation Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MySQL Redmi Docker Xiaomi OPPO Reno