Get the App
SLTechnology News&Howtos  ›  Servers  › 

What is the method of interconnecting Docker port mapping with containers

Shulou Source: shulou.com Published: 2022-05-31 19:54:47 10月03日 Update

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!

Tags: Containers methods ports interconnections learning content mirroring checking that is ideas situations data databases articles methods more knowledge points articles follow Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Xiaomi vpn OPPO Reno Huawei Shulou Information