Docker-None & Host network

This section introduces the None & Host network.

1 Introduction

Click here to return to the docker series article directory

Earlier we introduced the bridge network, this section continues to introduce none and host. These two are relatively simple and not very commonly used. Three networks were automatically created when Docker was installed:

[root@docker1 ~]# docker network ls
NETWORK ID        NAME         DRIVER       SCOPE
c1bb643c9c5a      bridge       bridge       local
59364623cee2      host         host         local
fb704391fb47      none         null         local

2.None network

Containers using the none network have only one lo network card, and the routing table is empty. In other words, this type of container cannot communicate with other containers and is a completely isolated container.
Its purpose is to perform host-wide calculations, and it can also be used by other network plugins (calico, weave) to disable docker's own network, thereby providing a network plugin's network stack.
Use none network to create a container, docker run -it -d --network=none --name=testnone busybox
and then check the network card:

[root@docker1 ~]# docker exec -it testnone sh
/ # ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever

It can be found that there is only one lo network card in the container, and the routing table is empty.

3.Host network

3.1 Introduction

Create a container with nginx image and use host network. Command: docker run -it -d --network=host --name=testhost nginx
Enter the container and execute ip a or ip r. The result you see is the same as the result executed directly on the host.
Test: Run curl 127.0.0.1:80 or curl 192.168.0.11:80 on the Host and return nginx welcome message. But it is not accessible on other machines.
note:

  1. Containers using the host network will not be assigned an IP address because it directly uses the IP address of the host;
  2. When using the host network, the publish port function is invalid.

4. Summary

  • This article introduces two other networks besides bridge, none and host, just understand.

In the next section, we introduce Docker's native overlay network. Click here to return to the docker series article directory .

 

Author original, please declare the source!


My WeChat public account updates cloud computing, container, network, programming and other articles at the same time. Welcome to visit!

 

Guess you like

Origin www.cnblogs.com/sunqingliang/p/12748691.html