Docker's four network types principle examples

Docker's four network types principle examples

Four network types:

  • None: Do not configure any network function for the container, --net=none
  • Container: Share the Network Namespace with another running container, --net=container:containerID (K8S)
  • Host: Share the Network Namespace with the host, --net=host
  • Bridge: NAT network model designed by Docker

The following are explained separately:

none:

[root@docker1 centos_zabbix]# docker run -it --network none centos6.9_ssh:v2 /bin/bash
[root@6ae597015723 /]# ip addr
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN qlen 1
  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

This kind of thing has no IP and can be played around in the container, which doesn't make much sense

Container type network:

[root@1c21de6080bb html]# [root@docker1 centos_zabbix]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
1c21de6080bb centos6.9_nginx_ssh:v3 "/bin/bash" 26 seconds ago Up 25 seconds vigorous_payne
[root@docker1 centos_zabbix]# docker run -it --network container:1c21de6080bb centos6.9_nginx_ssh:v4 /bin/bash
 
The IP address that shares the host name can view the properties [root@docker1 centos_zabbix]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
41c457f6b89d centos6.9_nginx_ssh:v4 "/bin/bash" 5 minutes ago Up 5 minutes loving_curie
1c21de6080bb centos6.9_nginx_ssh:v3 "/bin/bash" 6 minutes ago Up 6 minutes vigorous_payne
 
[root@docker1 centos_zabbix]# docker inspect 41c457f6b89d|grep -i network
      "NetworkMode": "container:1c21de6080bb8c83e800fa8b5fb15782a18bb61ab292050ca1172fbb866b1afc",
    "NetworkSettings": {
      "Networks": {}

It should be noted that whoever uses a port first will occupy it, and later users will not be able to use this port.

Host type

[root@docker1 centos_zabbix]# docker run -it --network=host centos6.9_nginx_ssh:v2 /bin/bash

This is to share the port with the host machine, whoever occupies it first will use it, but the performance is the highest, so we use this parameter when building the image, just to unify the network type and improve the efficiency of building the image

The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM.

You may also be interested in:
  • Detailed introduction to the docker network configuration process
  • Docker network principles and detailed analysis of custom networks
  • Docker container custom hosts network access operation
  • Docker custom network detailed introduction

<<:  jQuery achieves full screen scrolling effect

>>:  The perfect solution for forgetting the password in mysql8.0.19

Recommend

JavaScript to implement login slider verification

This article example shares the specific code of ...

MySQL max_allowed_packet setting

max_allowed_packet is a parameter in MySQL that i...

Solution to inconsistent display of cursor size in input box

The cursor size in the input box is inconsistent T...

JavaScript implementation of magnifying glass details

Table of contents 1. Rendering 2. Implementation ...

JavaScript to implement the aircraft war game

This article shares with you how to use canvas an...

How to install Nginx in CentOS

Official documentation: https://nginx.org/en/linu...

How to use Dockerfile to build images in Docker

Build the image Earlier we used various images fo...

Nginx configuration PC site mobile site separation to achieve redirection

Use nginx to configure the separation of PC site ...

Detailed explanation of the loading rules of the require method in node.js

Loading rules of require method Prioritize loadin...

Handwriting implementation of new in JS

Table of contents 1 Introduction to the new opera...

A brief discussion on ifnull() function similar to nvl() function in MySQL

IFNULL(expr1,expr2) If expr1 is not NULL, IFNULL(...