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

How to use HTML 5 drag and drop API in Vue

The Drag and Drop API adds draggable elements to ...

How to prevent event bubbling in JavaScript

What we need to pay attention to is that the char...

Use of Linux gzip command

1. Command Introduction The gzip (GNU zip) comman...

Detailed explanation of mysql integrity constraints example

This article describes the MySQL integrity constr...

JavaScript implements large file upload processing

Many times when we process file uploads, such as ...

Docker-compose installation db2 database operation

It is troublesome to install the db2 database dir...

How to center your HTML button

How to center your HTML button itself? This is ea...

A very detailed summary of communication between Vue components

Table of contents Preface 1. Props, $emit one-way...

Vue implements infinite loading waterfall flow

This article example shares the specific code of ...

An article to understand the usage of typeof in js

Table of contents Base Return Type String and Boo...

Mysql5.6.36 script compilation, installation and initialization tutorial

Overview This article is a script for automatical...