What is the method of interconnecting Docker port mapping with containers
This article mainly explains "what is the method of Docker port mapping and container interconnection". 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 "what is the method of Docker port mapping and container interconnection".
A new mydocker container is established, in which a mysql is installed and started. It is hoped that the container's mysql database can be accessed directly through centos.
Method one
[root@mysql01 ~] # docker inspect mydocker | grep-I ipaddre
"SecondaryIPAddresses": null
"IPAddress": "172.17.0.3"
"IPAddress": "172.17.0.3"
Configure forwarding:
[root@mysql01] # iptables-t nat-A DOCKER-p tcp-- dport 3388-j DNAT-- to-destination 172.17.0.3
Check:
[root@mysql01 ~] # docker port mydocker
[root@mysql01 ~] # netstat-nputl | grep-I 3388
[root@mysql01 ~] iptables-t nat-L-n (Port forwarding can be viewed in this way)
Method 2:
1. Save the mydocker container as a mirror first
Docker commit mydocker myimages
two。 Then restart a container mysql5.6.24 on the myimages image and specify the port mapping
Docker run-d-name mysql5.6.24-p 3366 it myimages 3306-it myimages / bin/bash
3. Check
[root@mysql01 ~] # netstat-nputl | grep-I 3366
Tcp6 0 0: 3366: * LISTEN 17673
[root@mysql01 ~] # docker port mysql5.6.24
3306/tcp-> 0.0.0.0pur3366
Thank you for reading, the above is the content of "what is the method of Docker port mapping and container interconnection". After the study of this article, I believe you have a deeper understanding of what is the method of Docker port mapping and container interconnection, 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!