Get the App
SLTechnology News&Howtos  ›  Servers  › 

Docker Foundation (3)-- basic Network Model

Shulou Source: shulou.com Published: 2022-06-03 04:20:25 10月01日 Update

Bridge (default)

Default option Therefore, there is no need to use the--network option, use the default docker0 bridge; you can access the external network, but the external network needs to pass through the firewall to access the local container;

[root@www ~]# docker run --rm --name bux1 --network bridge busybox:1.29 ifconfig -aeth0 Link encap:Ethernet HWaddr 02:42:AC:11:00:03 inet addr:172.17.0.3 Bcast:172.17.255.255 Mask:255.255.0.0 UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:2 errors:0 dropped:0 overruns:0 frame:0 TX packets:0 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:0 RX bytes:180 (180.0 B) TX bytes:0 (0.0 B) lo Link encap:Local Loopback inet addr:127.0.0.1 Mask:255.0.0.0 UP LOOPBACK RUNNING MTU:65536 Metric:1 RX packets:0 errors:0 dropped:0 overruns:0 frame:0 TX packets:0 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)

Port mapping:

[root@www ~]# docker container run --name ngx1 --rm -p 80 ljymyy/nginx

[root@www ~]# docker port ngx180/tcp -> 0.0.0.0:32768

2.

[root@www ~]# docker container run --name ngx1 --rm -p 80:80 ljymyy/nginx[root@www ~]# docker port ngx180/tcp -> 0.0.0.0:80

3.

[root@www ~]# docker container run --name ngx1 --rm -p 172.16.75.3::80 ljymyy/nginx[root@www ~]# docker port ngx180/tcp -> 172.16.75.3:32768

4.

[root@www ~]# docker container run --name ngx1 --rm -p 172.16.75.3:80:80 ljymyy/nginx[root@www ~]# docker port ngx180/tcp -> 172.16.75.3:80

5. Use the "-P" option to expose ports;

[root@www ~]# docker container run --name ngx1 --rm -P ljymyy/nginx[root@www ~]# docker port ngx180/tcp -> 0.0.0.0:32769

6. Use the "--expose" option to manually specify ports for exposure;

[root@www ~]# docker container run --name bux --rm -it -P --expose 123 --expose 678 busybox:1.29/ #[root@www ~]# docker port bux123/tcp -> 0.0.0.0:32771678/tcp -> 0.0.0.0:32770

NONE

Do not specify any IP address and port number, generally used for various offline operations such as data backup and recovery;

[root@www ~]# docker run --rm --name bux1 --network none busybox:1.29 ifconfig -alo Link encap:Local Loopback inet addr:127.0.0.1 Mask:255.0.0.0 UP LOOPBACK RUNNING MTU:65536 Metric:1 RX packets:0 errors:0 dropped:0 overruns:0 frame:0 TX packets:0 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)

Container

First let a container open port 2222; then use another container joined container, observe its port number;

[root@www ~]# docker run --name bux1 -d -p 2222 busybox:1.29 /bin/httpd -p 2222 -ff3c8d49bddc8a9f3597ef9ab6fcf2dbf4b8e3e831fa67803b06a95d7da0b5bfb[root@www ~]# docker run --name bux2 --network container:bux1 busybox:1.29 netstat -tanActive Internet connections (servers and established)Proto Recv-Q Send-Q Local Address Foreign Address State tcp 0 0 :::2222 :::* LISTEN

Tags: Port container slogan base address backup manual data firewall bridge open observation fire prevention model network Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno vpn Docker Shulou Information MariaDB Huawei