Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Example Analysis of Network Mode in docker

2025-02-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly introduces the example analysis of the network model in docker, which is very detailed and has a certain reference value. Interested friends must read it!

When you finish installing Docker, it automatically creates three networks.

Docker network ls

The results should be as follows:

NETWORK ID NAME DRIVER SCOPE594430d2d4bb bridge bridge locald855b34c5d51 host host localb1ecee29ed5e none null local

These three networks are built into Docker, which you can use to specify which networks the container should connect to when running the container.

When we use docker run to create a Docker container, we can use the-- network flag option to specify the network mode of the container. Docker has the following four network modes:

Host mode: specified using-- net=host.

None mode: specified using-- net=none.

Bridge mode: specified using-- net=bridge, default setting.

Container mode: specified using-- net=container:NAME_or_ID.

Host

Docker uses Linux's Namespaces technology to isolate resources, such as PID Namespace isolation process, Mount Namespace isolation file system, Network Namespace isolation network and so on. A Network Namespace provides an independent network environment, including network cards, routing, Iptable rules, etc. are isolated from other Network Namespace.

The host mode is similar to Vmware's bridging mode, which is on the same network as the host, but does not have a separate IP address. A Docker container typically allocates a separate Network Namespace. However, if you start the container in host mode, the container will not get a separate Network Namespace, but will share a Network Namespace with the host. The container will not virtualize its own network card or configure its own IP, but will use the IP and port of the host.

As shown in the following figure: the container and the host are under the same network namespace and use the same network protocol stack, and the container can directly use all the network interfaces of the host.

Case verification

View host link interfac

Ip a

The IP of the host in our right cloud environment is {host0.ip} / 24 to start the nginx container in host mode and listen to its tcp80 port.

Use the-- net host parameter to specify that the network model uses host mode

Docker run-- name=nginx-- net=host-p 80:80-d nginx

View the container link interface, consistent with the host

Docker exec-it nginx cat / etc/hosts

If outsiders want to access the application in the container, they can simply use {host0.ip}: 80 without any NAT conversion, just like running in the host. However, other aspects of the container, such as file systems, process lists, and so on, are isolated from the host.

Curl {host0.ip} above is all the content of the article "sample Analysis of Network patterns in docker". Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report