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
Table of contents 1. Global level 2. Database lev...
This article mainly introduces the relevant solut...
Each web page has an address, identified by a URL...
Table of contents 1. Master-slave synchronization...
1. Operating Environment vmware14pro Ubuntu 16.04...
Write a SQL first SELECT DISTINCT from_id FROM co...
Table of contents Safe Mode Settings test 1. Upda...
1. The mysqldump backup method uses logical backu...
CSS style: Copy code The code is as follows: <s...
If you have experience in vue2 project developmen...
Table of contents 1. Problem Description 2. Probl...
Preface: After studying the previous article, we ...
Install ZLMediaKit on centos6 The author of ZLMed...
ref definition: used to register reference inform...
I'm looking for a job!!! Advance preparation:...