Implementation of Docker container connection and communication

Implementation of Docker container connection and communication

Port mapping is not the only way to connect Docker to another container.

Docker has a connection system that allows multiple containers to be connected together and share connection information.

A docker connection creates a parent-child relationship where the parent container can see the child container's information.

Container naming

When we create a container, Docker will automatically name it. Alternatively, we can use the --name flag to name the container, for example:

runoob@runoob:~$ docker run -d -P --name runoob training/webapp python app.py
43780a6eabaaf14e590b6e849235c75f3012995403f97749775e38436db9a441

We can use the docker ps command to view the container name.

runoob@runoob:~$ docker ps -l
CONTAINER ID IMAGE COMMAND ... PORTS NAMES
43780a6eabaa training/webapp "python app.py" ... 0.0.0.0:32769->5000/tcp runoob

Create a new network

Let's create a new Docker network.

$ docker network create -d bridge test-net 

insert image description here

Parameter Description:

-d: The parameter specifies the Docker network type, which can be bridge or overlay.

The overlay network type is used for Swarm mode, and you can ignore it in this section.

Connecting Containers

Run a container and connect to the newly created test-net network:

$ docker run -itd --name test1 --network test-net ubuntu /bin/bash

Open a new terminal, run another container and join the test-net network:

$ docker run -itd --name test2 --network test-net ubuntu /bin/bash 

insert image description here

The following ping command is used to prove that the test1 container and the test2 container are interconnected.

If there is no ping command in the test1 and test2 containers, run the following command in the container to install ping (learn and use right away: you can install it in a container, submit the container to the image, and then re-run the above two containers with the new image).

apt-get update
apt install iputils-ping

Enter the following command in the test1 container:

Click on the image to see a larger version:

insert image description here

This is the end of this article about the implementation of Docker container connection and communication. For more relevant Docker container connection and communication content, please search 123WORDPRESS.COM's previous articles or continue to browse the following related articles. I hope everyone will support 123WORDPRESS.COM in the future!

You may also be interested in:
  • Operations of communication between Docker containers and external network communication
  • Detailed explanation of Docker container cross-host multi-network segment communication solution
  • Detailed explanation of direct routing in cross-host communication of Docker containers
  • Detailed explanation of how Docker containers communicate across hosts
  • Detailed explanation of a method of communication between docker containers
  • How to implement communication between Docker containers

<<:  HTML table tag tutorial (27): cell background image attribute BACKGROUND

>>:  A complete example of mysql querying batch data from one table and inserting it into another table

Recommend

A brief discussion on CSS cascading mechanism

Why does CSS have a cascading mechanism? Because ...

Summary of the use of html meta tags (recommended)

Meta tag function The META tag is a key tag in th...

The difference between name and value in input tag

type is the control used for input and output in t...

MySQL 8.0.21 installation tutorial with pictures and text

1. Download the download link Click download. You...

CSS sets the list style and creates the navigation menu implementation code

1. Set the list symbol list-style-type: attribute...

Detailed explanation of Vue router routing

Table of contents 1. Basic use 2. Several points ...

A performance bug about MySQL partition tables

Table of contents 2. Stack analysis using pt-pmap...

SQL implementation of LeetCode (197. Rising temperature)

[LeetCode] 197.Rising Temperature Given a Weather...

An example of the difference between the id and name attributes in input

I have been making websites for a long time, but I...

Complete step-by-step record of MySQL 8.0.26 installation and uninstallation

Table of contents Preface 1. Installation 1. Down...

How to use MySQL stress testing tools

1. MySQL's own stress testing tool - Mysqlsla...

MySQL uses events to complete scheduled tasks

Events can specify the execution of SQL code once...