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

Summary of the unknown usage of "!" in Linux

Preface In fact, the humble "!" has man...

Detailed explanation of the flexible use of CSS grid system in projects

Preface CSS grids are usually bundled in various ...

How to solve the problem of ERROR 2003 (HY000) when starting mysql

1. Problem Description When starting MYSQL, a pro...

How to completely delete the MySQL 8.0 service under Linux

Before reading this article, it is best to have a...

Summary of MySQL database like statement wildcard fuzzy query

MySQL error: Parameter index out of range (1 >...

Use iframe to submit form without refreshing the page

So we introduce an embedding framework to solve th...

JavaScript anti-shake and throttling detailed explanation

Table of contents Debounce Throttle Summarize Deb...

Nginx tp3.2.3 404 problem solution

Recently I changed Apache to nginx. When I moved ...

Detailed explanation of Vue's monitoring method case

Monitoring method in Vue watch Notice Name: You s...

React Hooks Detailed Explanation

Table of contents What are hooks? Class Component...

How to delete node_modules and reinstall

Table of contents Step 1: Install node_modules in...

Summary of MySQL stored procedure permission issues

MySQL stored procedures, yes, look like very rare...

How to mount a disk in Linux

When using a virtual machine, you may find that t...

Execution context and execution stack example explanation in JavaScript

JavaScript - Principles Series In daily developme...