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 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 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: 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:
|
<<: HTML table tag tutorial (27): cell background image attribute BACKGROUND
Take MySQL 5.7.19 installation as an example, fir...
Why does CSS have a cascading mechanism? Because ...
Meta tag function The META tag is a key tag in th...
type is the control used for input and output in t...
1. Download the download link Click download. You...
1. Set the list symbol list-style-type: attribute...
Table of contents Scenario Task idea analyze Conc...
Table of contents 1. Basic use 2. Several points ...
Table of contents 2. Stack analysis using pt-pmap...
[LeetCode] 197.Rising Temperature Given a Weather...
I have been making websites for a long time, but I...
Table of contents Preface 1. Installation 1. Down...
1. MySQL's own stress testing tool - Mysqlsla...
Events can specify the execution of SQL code once...
This article describes how to build a phalcon env...