欧美阿v视频在线大全_亚洲欧美中文日韩V在线观看_www性欧美日韩欧美91_亚洲欧美日韩久久精品

主頁 > 知識庫 > Docker網絡原理及自定義網絡詳細解析

Docker網絡原理及自定義網絡詳細解析

熱門標簽:打400電話怎么辦理收費 麗江真人語音電話外呼系統 宿城區電話機器人找哪家 上海申請高400開頭的電話 400電話辦理介紹信 怎么找到沒有地圖標注的店 10086外包用的什么外呼系統 河南防封號電銷機器人是什么 福州企業電銷機器人排名

Docker在宿主機上虛擬了一個網橋,當創建并啟動容器的時候,每一個容器默認都會被分配一個跟網橋網段一致的ip,網橋作為容器的網關,網橋與每一個容器聯通,容器間通過網橋可以通信。由于網橋是虛擬出來的,外網無法進行尋址,也就是默認外網無法訪問容器,需要在創建啟動容器時把宿主機的端口與容器端口進行映射,通過宿主機IP端口訪問容器。這是Docker默認的網絡,它有一個弊端是只能通過IP讓容器互相訪問,如果想使用容器名稱或容器ID互相訪問需要在創建啟動容器時候用link的方式修改hosts文件實現。一般使用自定義網絡,自定義網絡使用network創建,創建時可以指定子網網段及網關等信息,在創建并啟動容器時指定使用的網絡。這樣在一個自定義網絡里的所有容器可以直接使用容器名進行訪問,如果一個容器想要訪問其他網絡中的容器也可以在network中進行設置,這樣這個容器與目標網絡的容器可以使用容器名通信。

1 默認網絡docker0

用vm虛擬機測試,未啟動docker 系統中有兩個網絡(回環網絡、虛擬機網絡)

當啟動docker服務后,宿主機多出一個網絡docker0 這就是docker默認網絡

# 啟動docker服務
[root@localhost ~]# systemctl start docker

啟動一個tomcat容器,會發現宿主機又多出一個網絡

啟動tomcat
[root@localhost ~]# docker run -d -P --name tomcat1 tomcat

再啟動一個tomcat,會發展宿主機又多出一個網絡

# 啟動tomcat
[root@localhost ~]# docker run -d -P --name tomcat2 tomcat

測試兩個tomcat網絡ip是通的

# 查看tomcat的ip地址
[root@localhost ~]# docker exec -it tomcat2 ip addr
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default 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
9: eth0@if10: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default
    link/ether 02:42:ac:11:00:03 brd ff:ff:ff:ff:ff:ff link-netnsid 0
    inet 172.17.0.3/16 brd 172.17.255.255 scope global eth0
       valid_lft forever preferred_lft forever
# 在tomcat1 ping tomcat2的ip
[root@localhost ~]# docker exec -it tomcat1 ping 172.17.0.3
PING 172.17.0.3 (172.17.0.3) 56(84) bytes of data.
64 bytes from 172.17.0.3: icmp_seq=1 ttl=64 time=0.146 ms
64 bytes from 172.17.0.3: icmp_seq=2 ttl=64 time=0.067 ms
64 bytes from 172.17.0.3: icmp_seq=3 ttl=64 time=0.088 ms
^C
--- 172.17.0.3 ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 5ms
rtt min/avg/max/mdev = 0.067/0.100/0.146/0.034 ms

在tomcat1里ping tomcat2的 容器名無法ping通

# 在tomcat1里ping tomcat2的容器名
[root@localhost ~]# docker exec -it tomcat1 ping tomcat2
^C[root@localhost ~]#

停止tomcat1 重新創建啟動tomcat 使用link 會在底層修改tomcat1 的hosts文件 實現容器名作為ip域名從而tomcat1到tomcat2的單向ping通

# 刪除tomcat1
[root@localhost ~]# docker rm -f tomcat1
tomcat1
 
# 查看run的幫助文檔 link用法
[root@localhost ~]# docker run --help
 
Usage:  docker run [OPTIONS] IMAGE [COMMAND] [ARG...]
 
Run a command in a new container
 
Options:
      --add-host list                  Add a custom host-to-IP mapping (host:ip)
  -a, --attach list                    Attach to STDIN, STDOUT or STDERR
      --blkio-weight uint16            Block IO (relative weight), between 10 and 1000, or 0 to disable (default 0)
      --blkio-weight-device list       Block IO weight (relative device weight) (default [])
      --cap-add list                   Add Linux capabilities
      --cap-drop list                  Drop Linux capabilities
      --cgroup-parent string           Optional parent cgroup for the container
      --cgroupns string                Cgroup namespace to use (host|private)
                                       'host':    Run the container in the Docker host's cgroup namespace
                                       'private': Run the container in its own private cgroup namespace
                                       '':        Use the cgroup namespace as configured by the
                                                  default-cgroupns-mode option on the daemon (default)
      --cidfile string                 Write the container ID to the file
      --cpu-period int                 Limit CPU CFS (Completely Fair Scheduler) period
      --cpu-quota int                  Limit CPU CFS (Completely Fair Scheduler) quota
      --cpu-rt-period int              Limit CPU real-time period in microseconds
      --cpu-rt-runtime int             Limit CPU real-time runtime in microseconds
  -c, --cpu-shares int                 CPU shares (relative weight)
      --cpus decimal                   Number of CPUs
      --cpuset-cpus string             CPUs in which to allow execution (0-3, 0,1)
      --cpuset-mems string             MEMs in which to allow execution (0-3, 0,1)
  -d, --detach                         Run container in background and print container ID
      --detach-keys string             Override the key sequence for detaching a container
      --device list                    Add a host device to the container
      --device-cgroup-rule list        Add a rule to the cgroup allowed devices list
      --device-read-bps list           Limit read rate (bytes per second) from a device (default [])
      --device-read-iops list          Limit read rate (IO per second) from a device (default [])
      --device-write-bps list          Limit write rate (bytes per second) to a device (default [])
      --device-write-iops list         Limit write rate (IO per second) to a device (default [])
      --disable-content-trust          Skip image verification (default true)
      --dns list                       Set custom DNS servers
      --dns-option list                Set DNS options
      --dns-search list                Set custom DNS search domains
      --domainname string              Container NIS domain name
      --entrypoint string              Overwrite the default ENTRYPOINT of the image
  -e, --env list                       Set environment variables
      --env-file list                  Read in a file of environment variables
      --expose list                    Expose a port or a range of ports
      --gpus gpu-request               GPU devices to add to the container ('all' to pass all GPUs)
      --group-add list                 Add additional groups to join
      --health-cmd string              Command to run to check health
      --health-interval duration       Time between running the check (ms|s|m|h) (default 0s)
      --health-retries int             Consecutive failures needed to report unhealthy
      --health-start-period duration   Start period for the container to initialize before starting health-retries countdown
                                       (ms|s|m|h) (default 0s)
      --health-timeout duration        Maximum time to allow one check to run (ms|s|m|h) (default 0s)
      --help                           Print usage
  -h, --hostname string                Container host name
      --init                           Run an init inside the container that forwards signals and reaps processes
  -i, --interactive                    Keep STDIN open even if not attached
      --ip string                      IPv4 address (e.g., 172.30.100.104)
      --ip6 string                     IPv6 address (e.g., 2001:db8::33)
      --ipc string                     IPC mode to use
      --isolation string               Container isolation technology
      --kernel-memory bytes            Kernel memory limit
  -l, --label list                     Set meta data on a container
      --label-file list                Read in a line delimited file of labels
      --link list                      Add link to another container
      --link-local-ip list             Container IPv4/IPv6 link-local addresses
      --log-driver string              Logging driver for the container
      --log-opt list                   Log driver options
      --mac-address string             Container MAC address (e.g., 92:d0:c6:0a:29:33)
  -m, --memory bytes                   Memory limit
      --memory-reservation bytes       Memory soft limit
      --memory-swap bytes              Swap limit equal to memory plus swap: '-1' to enable unlimited swap
      --memory-swappiness int          Tune container memory swappiness (0 to 100) (default -1)
      --mount mount                    Attach a filesystem mount to the container
      --name string                    Assign a name to the container
      --network network                Connect a container to a network
      --network-alias list             Add network-scoped alias for the container
      --no-healthcheck                 Disable any container-specified HEALTHCHECK
      --oom-kill-disable               Disable OOM Killer
      --oom-score-adj int              Tune host's OOM preferences (-1000 to 1000)
      --pid string                     PID namespace to use
      --pids-limit int                 Tune container pids limit (set -1 for unlimited)
      --platform string                Set platform if server is multi-platform capable
      --privileged                     Give extended privileges to this container
  -p, --publish list                   Publish a container's port(s) to the host
  -P, --publish-all                    Publish all exposed ports to random ports
      --pull string                    Pull image before running ("always"|"missing"|"never") (default "missing")
      --read-only                      Mount the container's root filesystem as read only
      --restart string                 Restart policy to apply when a container exits (default "no")
      --rm                             Automatically remove the container when it exits
      --runtime string                 Runtime to use for this container
      --security-opt list              Security Options
      --shm-size bytes                 Size of /dev/shm
      --sig-proxy                      Proxy received signals to the process (default true)
      --stop-signal string             Signal to stop a container (default "SIGTERM")
      --stop-timeout int               Timeout (in seconds) to stop a container
      --storage-opt list               Storage driver options for the container
      --sysctl map                     Sysctl options (default map[])
      --tmpfs list                     Mount a tmpfs directory
  -t, --tty                            Allocate a pseudo-TTY
      --ulimit ulimit                  Ulimit options (default [])
  -u, --user string                    Username or UID (format: <name|uid>[:<group|gid>])
      --userns string                  User namespace to use
      --uts string                     UTS namespace to use
  -v, --volume list                    Bind mount a volume
      --volume-driver string           Optional volume driver for the container
      --volumes-from list              Mount volumes from the specified container(s)
  -w, --workdir string                 Working directory inside the container
 
# 啟動tomcat1 link指定要訪問的容器名
[root@localhost ~]# docker run -d -P --name tomcat1 --link tomcat2 tomcat
f78c51961662a1d3558fc8d0d95906b902a7a042f251a60858e72bcfa62e7a08
 
# 測試ping
[root@localhost ~]# docker exec -it tomcat1 ping tomcat2
PING tomcat2 (172.17.0.3) 56(84) bytes of data.
64 bytes from tomcat2 (172.17.0.3): icmp_seq=1 ttl=64 time=0.088 ms
64 bytes from tomcat2 (172.17.0.3): icmp_seq=2 ttl=64 time=0.071 ms
64 bytes from tomcat2 (172.17.0.3): icmp_seq=3 ttl=64 time=0.071 ms
^C
--- tomcat2 ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 1000ms
rtt min/avg/max/mdev = 0.071/0.076/0.088/0.012 ms
 
# 查看tomcat1的hosts已經加入了tomcat2的域名
[root@localhost ~]# docker exec -it tomcat1 cat /etc/hosts
127.0.0.1       localhost
::1     localhost ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
172.17.0.3      tomcat2 27766c324de6
172.17.0.2      f78c51961662
 
# tomcat2無法ping通tomcat1
[root@localhost ~]# docker exec -it tomcat2 ping tomcat1
^C[root@localhost ~]#

2 自定義網絡

需要用到network命令

# 查看幫助文檔
[root@localhost ~]# docker network --help
 
Usage:  docker network COMMAND
 
Manage networks
 
Commands:
  connect     Connect a container to a network
  create      Create a network
  disconnect  Disconnect a container from a network
  inspect     Display detailed information on one or more networks
  ls          List networks
  prune       Remove all unused networks
  rm          Remove one or more networks
 
Run 'docker network COMMAND --help' for more information on a command.

列出當前的docker網絡 bridge為 默認網絡docker0

[root@localhost ~]# docker network ls
NETWORK ID     NAME      DRIVER    SCOPE
9b27ff0926bf   bridge    bridge    local
8dfa2efae677   host      host      local
2025b7fb1d7c   none      null      local

創建網絡mynet

[root@localhost ~]# docker network create --help
 
Usage:  docker network create [OPTIONS] NETWORK
 
Create a network
 
Options:
      --attachable           Enable manual container attachment
      --aux-address map      Auxiliary IPv4 or IPv6 addresses used by Network driver (default map[])
      --config-from string   The network from which to copy the configuration
      --config-only          Create a configuration only network
  -d, --driver string        Driver to manage the Network (default "bridge")
      --gateway strings      IPv4 or IPv6 Gateway for the master subnet
      --ingress              Create swarm routing-mesh network
      --internal             Restrict external access to the network
      --ip-range strings     Allocate container ip from a sub-range
      --ipam-driver string   IP Address Management Driver (default "default")
      --ipam-opt map         Set IPAM driver specific options (default map[])
      --ipv6                 Enable IPv6 networking
      --label list           Set metadata on a network
  -o, --opt map              Set driver specific options (default map[])
      --scope string         Control the network's scope
      --subnet strings       Subnet in CIDR format that represents a network segment
[root@localhost ~]# docker network create --driver bridge --subnet 192.168.0.0/16 --gateway 192.168.0.1 mynet
1abaa8e6a387bc8bbc7ac50d9f2289e96a143a92f074e90f698bd70411c86672
[root@localhost ~]# docker network inspect mynet
[
    {
        "Name": "mynet",
        "Id": "1abaa8e6a387bc8bbc7ac50d9f2289e96a143a92f074e90f698bd70411c86672",
        "Created": "2021-05-13T11:21:13.494039122+08:00",
        "Scope": "local",
        "Driver": "bridge",
        "EnableIPv6": false,
        "IPAM": {
            "Driver": "default",
            "Options": {},
            "Config": [
                {
                    "Subnet": "192.168.0.0/16",
                    "Gateway": "192.168.0.1"
                }
            ]
        },
        "Internal": false,
        "Attachable": false,
        "Ingress": false,
        "ConfigFrom": {
            "Network": ""
        },
        "ConfigOnly": false,
        "Containers": {},
        "Options": {},
        "Labels": {}
    }
]

使用mynet創建啟動兩個tomcat,他們可以直接通過容器名稱雙向互相ping通

[root@localhost ~]# docker run --help
 
Usage:  docker run [OPTIONS] IMAGE [COMMAND] [ARG...]
 
Run a command in a new container
 
Options:
      --add-host list                  Add a custom host-to-IP mapping (host:ip)
  -a, --attach list                    Attach to STDIN, STDOUT or STDERR
      --blkio-weight uint16            Block IO (relative weight), between 10 and 1000, or 0 to disable (default 0)
      --blkio-weight-device list       Block IO weight (relative device weight) (default [])
      --cap-add list                   Add Linux capabilities
      --cap-drop list                  Drop Linux capabilities
      --cgroup-parent string           Optional parent cgroup for the container
      --cgroupns string                Cgroup namespace to use (host|private)
                                       'host':    Run the container in the Docker host's cgroup namespace
                                       'private': Run the container in its own private cgroup namespace
                                       '':        Use the cgroup namespace as configured by the
                                                  default-cgroupns-mode option on the daemon (default)
      --cidfile string                 Write the container ID to the file
      --cpu-period int                 Limit CPU CFS (Completely Fair Scheduler) period
      --cpu-quota int                  Limit CPU CFS (Completely Fair Scheduler) quota
      --cpu-rt-period int              Limit CPU real-time period in microseconds
      --cpu-rt-runtime int             Limit CPU real-time runtime in microseconds
  -c, --cpu-shares int                 CPU shares (relative weight)
      --cpus decimal                   Number of CPUs
      --cpuset-cpus string             CPUs in which to allow execution (0-3, 0,1)
      --cpuset-mems string             MEMs in which to allow execution (0-3, 0,1)
  -d, --detach                         Run container in background and print container ID
      --detach-keys string             Override the key sequence for detaching a container
      --device list                    Add a host device to the container
      --device-cgroup-rule list        Add a rule to the cgroup allowed devices list
      --device-read-bps list           Limit read rate (bytes per second) from a device (default [])
      --device-read-iops list          Limit read rate (IO per second) from a device (default [])
      --device-write-bps list          Limit write rate (bytes per second) to a device (default [])
      --device-write-iops list         Limit write rate (IO per second) to a device (default [])
      --disable-content-trust          Skip image verification (default true)
      --dns list                       Set custom DNS servers
      --dns-option list                Set DNS options
      --dns-search list                Set custom DNS search domains
      --domainname string              Container NIS domain name
      --entrypoint string              Overwrite the default ENTRYPOINT of the image
  -e, --env list                       Set environment variables
      --env-file list                  Read in a file of environment variables
      --expose list                    Expose a port or a range of ports
      --gpus gpu-request               GPU devices to add to the container ('all' to pass all GPUs)
      --group-add list                 Add additional groups to join
      --health-cmd string              Command to run to check health
      --health-interval duration       Time between running the check (ms|s|m|h) (default 0s)
      --health-retries int             Consecutive failures needed to report unhealthy
      --health-start-period duration   Start period for the container to initialize before starting health-retries countdown
                                       (ms|s|m|h) (default 0s)
      --health-timeout duration        Maximum time to allow one check to run (ms|s|m|h) (default 0s)
      --help                           Print usage
  -h, --hostname string                Container host name
      --init                           Run an init inside the container that forwards signals and reaps processes
  -i, --interactive                    Keep STDIN open even if not attached
      --ip string                      IPv4 address (e.g., 172.30.100.104)
      --ip6 string                     IPv6 address (e.g., 2001:db8::33)
      --ipc string                     IPC mode to use
      --isolation string               Container isolation technology
      --kernel-memory bytes            Kernel memory limit
  -l, --label list                     Set meta data on a container
      --label-file list                Read in a line delimited file of labels
      --link list                      Add link to another container
      --link-local-ip list             Container IPv4/IPv6 link-local addresses
      --log-driver string              Logging driver for the container
      --log-opt list                   Log driver options
      --mac-address string             Container MAC address (e.g., 92:d0:c6:0a:29:33)
  -m, --memory bytes                   Memory limit
      --memory-reservation bytes       Memory soft limit
      --memory-swap bytes              Swap limit equal to memory plus swap: '-1' to enable unlimited swap
      --memory-swappiness int          Tune container memory swappiness (0 to 100) (default -1)
      --mount mount                    Attach a filesystem mount to the container
      --name string                    Assign a name to the container
      --network network                Connect a container to a network
      --network-alias list             Add network-scoped alias for the container
      --no-healthcheck                 Disable any container-specified HEALTHCHECK
      --oom-kill-disable               Disable OOM Killer
      --oom-score-adj int              Tune host's OOM preferences (-1000 to 1000)
      --pid string                     PID namespace to use
      --pids-limit int                 Tune container pids limit (set -1 for unlimited)
      --platform string                Set platform if server is multi-platform capable
      --privileged                     Give extended privileges to this container
  -p, --publish list                   Publish a container's port(s) to the host
  -P, --publish-all                    Publish all exposed ports to random ports
      --pull string                    Pull image before running ("always"|"missing"|"never") (default "missing")
      --read-only                      Mount the container's root filesystem as read only
      --restart string                 Restart policy to apply when a container exits (default "no")
      --rm                             Automatically remove the container when it exits
      --runtime string                 Runtime to use for this container
      --security-opt list              Security Options
      --shm-size bytes                 Size of /dev/shm
      --sig-proxy                      Proxy received signals to the process (default true)
      --stop-signal string             Signal to stop a container (default "SIGTERM")
      --stop-timeout int               Timeout (in seconds) to stop a container
      --storage-opt list               Storage driver options for the container
      --sysctl map                     Sysctl options (default map[])
      --tmpfs list                     Mount a tmpfs directory
  -t, --tty                            Allocate a pseudo-TTY
      --ulimit ulimit                  Ulimit options (default [])
  -u, --user string                    Username or UID (format: <name|uid>[:<group|gid>])
      --userns string                  User namespace to use
      --uts string                     UTS namespace to use
  -v, --volume list                    Bind mount a volume
      --volume-driver string           Optional volume driver for the container
      --volumes-from list              Mount volumes from the specified container(s)
  -w, --workdir string                 Working directory inside the container
[root@localhost ~]# docker run -d -P --name tomcat-n-1 --network mynet tomcat
404e4e63622b207af2ed534e768996f4d1cba4c798bba9e5d9b33c42711eaa4a
[root@localhost ~]# docker run -d -P --name tomcat-n-2 --network mynet tomcat
f6352fb3db01beed6ddf17ef84999a4ab209f026a6137b3bc7e35335d434785f
[root@localhost ~]# docker ps
CONTAINER ID   IMAGE     COMMAND             CREATED          STATUS          PORTS                                         NAMES
f6352fb3db01   tomcat    "catalina.sh run"   3 seconds ago    Up 2 seconds    0.0.0.0:49159->8080/tcp, :::49159->8080/tcp   tomcat-n-2
404e4e63622b   tomcat    "catalina.sh run"   10 seconds ago   Up 9 seconds    0.0.0.0:49158->8080/tcp, :::49158->8080/tcp   tomcat-n-1
f78c51961662   tomcat    "catalina.sh run"   15 minutes ago   Up 15 minutes   0.0.0.0:49157->8080/tcp, :::49157->8080/tcp   tomcat1
27766c324de6   tomcat    "catalina.sh run"   16 minutes ago   Up 16 minutes   0.0.0.0:49156->8080/tcp, :::49156->8080/tcp   tomcat2
[root@localhost ~]# docker exec -it tomcat-n-1 ping tomcat-n-2
PING tomcat-n-2 (192.168.0.3) 56(84) bytes of data.
64 bytes from tomcat-n-2.mynet (192.168.0.3): icmp_seq=1 ttl=64 time=0.102 ms
64 bytes from tomcat-n-2.mynet (192.168.0.3): icmp_seq=2 ttl=64 time=0.069 ms
64 bytes from tomcat-n-2.mynet (192.168.0.3): icmp_seq=3 ttl=64 time=0.164 ms
^C
--- tomcat-n-2 ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 3ms
rtt min/avg/max/mdev = 0.069/0.111/0.164/0.041 ms

查看mynet網絡的詳細信息,包含了啟動的兩個tomcat容器的網絡信息

[root@localhost ~]# docker network inspect mynet
[
    {
        "Name": "mynet",
        "Id": "1abaa8e6a387bc8bbc7ac50d9f2289e96a143a92f074e90f698bd70411c86672",
        "Created": "2021-05-13T11:21:13.494039122+08:00",
        "Scope": "local",
        "Driver": "bridge",
        "EnableIPv6": false,
        "IPAM": {
            "Driver": "default",
            "Options": {},
            "Config": [
                {
                    "Subnet": "192.168.0.0/16",
                    "Gateway": "192.168.0.1"
                }
            ]
        },
        "Internal": false,
        "Attachable": false,
        "Ingress": false,
        "ConfigFrom": {
            "Network": ""
        },
        "ConfigOnly": false,
        "Containers": {
            "404e4e63622b207af2ed534e768996f4d1cba4c798bba9e5d9b33c42711eaa4a": {
                "Name": "tomcat-n-1",
                "EndpointID": "b9efbd78daabe9345ade2a2e55291b7646d01679516e2f0be1efd5c2d6fea6b8",
                "MacAddress": "02:42:c0:a8:00:02",
                "IPv4Address": "192.168.0.2/16",
                "IPv6Address": ""
            },
            "f6352fb3db01beed6ddf17ef84999a4ab209f026a6137b3bc7e35335d434785f": {
                "Name": "tomcat-n-2",
                "EndpointID": "6b05a1ceff43514305bf3d0adf9e30ba8007db5ec8349d47f96ff2b216912fc0",
                "MacAddress": "02:42:c0:a8:00:03",
                "IPv4Address": "192.168.0.3/16",
                "IPv6Address": ""
            }
        },
        "Options": {},
        "Labels": {}
    }
]

啟動一個tomcat3使用默認網絡docker0

[root@localhost ~]# docker run -d -P --name tomcat3 tomcat
90e94ac30a3c61b493d2ea38c32cf5dddb781e88c30547b609db765b15d7d1e0
[root@localhost ~]# docker network ls
NETWORK ID     NAME      DRIVER    SCOPE
9b27ff0926bf   bridge    bridge    local
8dfa2efae677   host      host      local
1abaa8e6a387   mynet     bridge    local
2025b7fb1d7c   none      null      local
 
# 查看docker0詳細信息 tomcat3出現在默認網絡里
[root@localhost ~]# docker network inspect 9b27ff0926bf
[
    {
        "Name": "bridge",
        "Id": "9b27ff0926bf22d0828ccd07d6e14eb17d96a4989f9def6f9118c099cf1ca1c6",
        "Created": "2021-05-13T10:51:20.244232273+08:00",
        "Scope": "local",
        "Driver": "bridge",
        "EnableIPv6": false,
        "IPAM": {
            "Driver": "default",
            "Options": null,
            "Config": [
                {
                    "Subnet": "172.17.0.0/16",
                    "Gateway": "172.17.0.1"
                }
            ]
        },
        "Internal": false,
        "Attachable": false,
        "Ingress": false,
        "ConfigFrom": {
            "Network": ""
        },
        "ConfigOnly": false,
        "Containers": {
            "27766c324de619b24e2ed522d8064c5a4610c8f509ff0aed8fa1719691f01bf1": {
                "Name": "tomcat2",
                "EndpointID": "de913778ce2d7478e25daca26809aa75c9093c43853d9420c70886fb16741722",
                "MacAddress": "02:42:ac:11:00:03",
                "IPv4Address": "172.17.0.3/16",
                "IPv6Address": ""
            },
            "90e94ac30a3c61b493d2ea38c32cf5dddb781e88c30547b609db765b15d7d1e0": {
                "Name": "tomcat3",
                "EndpointID": "2223e522a0950b846bb7691b31f60bbd88ab3c9b8e71d601a495cce39387b8cc",
                "MacAddress": "02:42:ac:11:00:04",
                "IPv4Address": "172.17.0.4/16",
                "IPv6Address": ""
            },
            "f78c51961662a1d3558fc8d0d95906b902a7a042f251a60858e72bcfa62e7a08": {
                "Name": "tomcat1",
                "EndpointID": "59299fdca5497e55dc5a94e408529cc98819b673568720c81aa1c554dff1bbe5",
                "MacAddress": "02:42:ac:11:00:02",
                "IPv4Address": "172.17.0.2/16",
                "IPv6Address": ""
            }
        },
        "Options": {
            "com.docker.network.bridge.default_bridge": "true",
            "com.docker.network.bridge.enable_icc": "true",
            "com.docker.network.bridge.enable_ip_masquerade": "true",
            "com.docker.network.bridge.host_binding_ipv4": "0.0.0.0",
            "com.docker.network.bridge.name": "docker0",
            "com.docker.network.driver.mtu": "1500"
        },
        "Labels": {}
    }
]

tomcat3和mynet不在一個網絡,tomcat3無法訪問mynet網絡里的兩個tomcat,可以使用network打通tomcat3和mynetwork,實現雙向互相訪問(支持容器名稱)。

# 查看mynet網絡里容器的ip
[root@localhost ~]# docker network inspect mynet
[
    {
        "Name": "mynet",
        "Id": "1abaa8e6a387bc8bbc7ac50d9f2289e96a143a92f074e90f698bd70411c86672",
        "Created": "2021-05-13T11:21:13.494039122+08:00",
        "Scope": "local",
        "Driver": "bridge",
        "EnableIPv6": false,
        "IPAM": {
            "Driver": "default",
            "Options": {},
            "Config": [
                {
                    "Subnet": "192.168.0.0/16",
                    "Gateway": "192.168.0.1"
                }
            ]
        },
        "Internal": false,
        "Attachable": false,
        "Ingress": false,
        "ConfigFrom": {
            "Network": ""
        },
        "ConfigOnly": false,
        "Containers": {
            "404e4e63622b207af2ed534e768996f4d1cba4c798bba9e5d9b33c42711eaa4a": {
                "Name": "tomcat-n-1",
                "EndpointID": "b9efbd78daabe9345ade2a2e55291b7646d01679516e2f0be1efd5c2d6fea6b8",
                "MacAddress": "02:42:c0:a8:00:02",
                "IPv4Address": "192.168.0.2/16",
                "IPv6Address": ""
            },
            "f6352fb3db01beed6ddf17ef84999a4ab209f026a6137b3bc7e35335d434785f": {
                "Name": "tomcat-n-2",
                "EndpointID": "6b05a1ceff43514305bf3d0adf9e30ba8007db5ec8349d47f96ff2b216912fc0",
                "MacAddress": "02:42:c0:a8:00:03",
                "IPv4Address": "192.168.0.3/16",
                "IPv6Address": ""
            }
        },
        "Options": {},
        "Labels": {}
    }
]
 
# tomcat3 ping ip不通
[root@localhost ~]# docker exec -it tomcat3 ping 192.168.0.2
PING 192.168.0.2 (192.168.0.2) 56(84) bytes of data.
^C
--- 192.168.0.2 ping statistics ---
7 packets transmitted, 0 received, 100% packet loss, time 11ms
 
[root@localhost ~]# docker exec -it tomcat3 ping 192.168.0.3
PING 192.168.0.3 (192.168.0.3) 56(84) bytes of data.
^C
--- 192.168.0.3 ping statistics ---
9 packets transmitted, 0 received, 100% packet loss, time 20ms
# 使用connect聯通一個網絡和另外一個網絡里的容器,可以互相容器名稱訪問
[root@localhost ~]# docker network connect --help
 
Usage:  docker network connect [OPTIONS] NETWORK CONTAINER
 
Connect a container to a network
 
Options:
      --alias strings           Add network-scoped alias for the container
      --driver-opt strings      driver options for the network
      --ip string               IPv4 address (e.g., 172.30.100.104)
      --ip6 string              IPv6 address (e.g., 2001:db8::33)
      --link list               Add link to another container
      --link-local-ip strings   Add a link-local address for the container
[root@localhost ~]# docker network connect mynet tomcat3
[root@localhost ~]# docker exec -it tomcat3 ping tomcat-n-1
PING tomcat-n-1 (192.168.0.2) 56(84) bytes of data.
64 bytes from tomcat-n-1.mynet (192.168.0.2): icmp_seq=1 ttl=64 time=0.235 ms
64 bytes from tomcat-n-1.mynet (192.168.0.2): icmp_seq=2 ttl=64 time=0.070 ms
64 bytes from tomcat-n-1.mynet (192.168.0.2): icmp_seq=3 ttl=64 time=0.064 ms
^C
--- tomcat-n-1 ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 6ms
rtt min/avg/max/mdev = 0.064/0.123/0.235/0.079 ms
[root@localhost ~]# docker exec -it tomcat-n-1 ping tomcat3
PING tomcat3 (192.168.0.4) 56(84) bytes of data.
64 bytes from tomcat3.mynet (192.168.0.4): icmp_seq=1 ttl=64 time=0.055 ms
64 bytes from tomcat3.mynet (192.168.0.4): icmp_seq=2 ttl=64 time=0.169 ms
64 bytes from tomcat3.mynet (192.168.0.4): icmp_seq=3 ttl=64 time=0.194 ms
^C
--- tomcat3 ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 6ms
rtt min/avg/max/mdev = 0.055/0.139/0.194/0.061 ms

以上就是Docker網絡原理及自定義網絡詳細解析的詳細內容,更多關于docker網絡原理的資料請關注腳本之家其它相關文章!

標簽:荊門 面試通知 隴南 連云港 朝陽 遵義 運城 雞西

巨人網絡通訊聲明:本文標題《Docker網絡原理及自定義網絡詳細解析》,本文關鍵詞  Docker,網絡,原理,及,自定義,;如發現本文內容存在版權問題,煩請提供相關信息告之我們,我們將及時溝通與處理。本站內容系統采集于網絡,涉及言論、版權與本站無關。
  • 相關文章
  • 下面列出與本文章《Docker網絡原理及自定義網絡詳細解析》相關的同類信息!
  • 本頁收集關于Docker網絡原理及自定義網絡詳細解析的相關信息資訊供網民參考!
  • 推薦文章
    欧美阿v视频在线大全_亚洲欧美中文日韩V在线观看_www性欧美日韩欧美91_亚洲欧美日韩久久精品
  • <rt id="w000q"><acronym id="w000q"></acronym></rt>
  • <abbr id="w000q"></abbr>
    <rt id="w000q"></rt>
    在线观看xxx| 欧美激情一区二区三区四区| 欧美人与z0zoxxxx视频| 欧美精品在线视频| 久久综合视频网| 欧美国产日韩亚洲一区| 精品一区二区免费| 成人免费视频视频在线观看免费 | 舔着乳尖日韩一区| 秋霞av亚洲一区二区三| 久久91精品久久久久久秒播| 给我看免费高清在线观看| 五月天精品视频| 色综合天天做天天爱| 欧美精品久久久久久久多人混战 | 欧美熟妇精品一区二区| 波多野结衣加勒比| 小早川怜子一区二区的演员表| 欧美日韩精品免费| 亚洲国产精品人人做人人爽| 婷婷成人综合网| www.555国产精品免费| 免费成年人视频在线观看| 欧美日韩精品电影| 香蕉影视欧美成人| 91免费版在线看| 无码国产69精品久久久久同性| 色呦呦一区二区三区| 欧美一区中文字幕| 国产精品理伦片| 美女国产一区二区| 中文字幕一区二区三区乱码不卡| 欧美日韩国产一级片| 日日摸夜夜添夜夜添精品视频| 欧美亚洲免费在线一区| 在线成人午夜影院| 免费观看一级欧美片| 欧美三级视频网站| 91精品国产入口| 亚洲自拍与偷拍| 97久久人人超碰| 免费成人美女女在线观看| 中文字幕亚洲一区二区av在线| 麻豆免费精品视频| 99鲁鲁精品一区二区三区| 久久久久久久久久久久电影 | 日韩福利电影在线观看| 国产精品一区二区在线免费观看| 男人操女人的视频网站| 亚洲一区在线免费观看| 欧美丰满少妇人妻精品| 欧美激情中文字幕| 国产精品一区二区久久不卡| 中文字幕一二三四区| 91精品国产乱码久久蜜臀| 韩国精品在线观看| 人人爽人人爽人人片| 自拍偷在线精品自拍偷无码专区| 粉嫩av一区二区三区| av免费播放网站| 亚洲黄色av一区| 国产欧美一区二区精品性色 | 精品一区精品二区高清| 色综合久久综合网97色综合| 天天影视涩香欲综合网| 国产激情无码一区二区三区| 亚洲成av人片在线| 小嫩苞一区二区三区| 亚洲综合在线免费观看| av不卡免费电影| 色噜噜狠狠色综合欧洲selulu | 日本道色综合久久| 一区二区三区中文字幕精品精品 | 大地资源二中文在线影视观看| 国产欧美精品一区二区色综合朱莉| 国产裸体视频网站| 欧美男女性生活在线直播观看| 国内精品伊人久久久久影院对白| 欧美三级韩国三级日本一级| 天天综合天天综合色| 日韩激情小视频| 日韩在线一区二区三区| 中文字幕影音先锋| 精油按摩中文字幕久久| 欧美日韩精品欧美日韩精品 | 欧美男男青年gay1069videost | 日韩精品一区二区三区视频| 亚洲自拍都市欧美小说| 香蕉成人在线视频| 亚洲桃色在线一区| 天天操天天舔天天射| 偷拍与自拍一区| 色噜噜狠狠成人中文综合| 国产伦理精品不卡| 99鲁鲁精品一区二区三区| 麻豆精品一区二区av白丝在线| 欧美丝袜丝交足nylons图片| 国产成人夜色高潮福利影视| 在线观看免费一区| 亚洲成人第一页| 国产黄色片在线免费观看| 韩国女主播成人在线| 欧美一区二区三区不卡| 91热门视频在线观看| 国产精品麻豆99久久久久久| 人妻少妇无码精品视频区| 午夜久久久久久久久| 在线观看视频91| 波多野结衣精品在线| 欧美精品日韩综合在线| 99精品国产一区二区三区不卡| 日本一区二区三区在线观看| 亚洲人人夜夜澡人人爽| 国产精品日韩精品欧美在线| 国产精品无码无卡无需播放器| 亚洲免费电影在线| 中文幕无线码中文字蜜桃| 五月天精品一区二区三区| 欧美日韩视频专区在线播放| 91麻豆国产香蕉久久精品| 亚洲天堂成人在线观看| 欧美三级在线免费观看| 欧美色倩网站大全免费| 午夜视频在线观看一区二区| 色老头久久综合| 99久久久精品| 亚洲人成伊人成综合网小说| 91成人福利视频| 日韩精品一级中文字幕精品视频免费观看| 翔田千里88av中文字幕| 风间由美中文字幕在线看视频国产欧美| 久久久www免费人成精品| 欧美黄色激情视频| 久久电影国产免费久久电影| 中文字幕在线2021| 成人免费高清在线| 日韩理论电影院| 在线观看中文字幕不卡| 91免费视频网址| 五月天一区二区三区| 日韩视频免费观看高清在线视频| 国产成人免费视频精品含羞草妖精| 久久精品在这里| 午夜剧场免费在线观看| 成人黄色大片在线观看| 亚洲男人的天堂在线观看| 欧美三级电影网站| 精品国产av色一区二区深夜久久| 亚洲视频精选在线| 欧美午夜电影在线播放| 亚洲激情 欧美| 麻豆国产欧美一区二区三区| 久久久天堂av| 国产精品 欧美激情| 91免费视频观看| 日本午夜一本久久久综合| 精品国产精品一区二区夜夜嗨| 精品人妻伦一二三区久| 欧美aaaaa成人免费观看视频| 久久亚洲春色中文字幕久久久| 多男操一女视频| 亚洲丝袜在线观看| 日韩成人一级大片| 国产日产欧美一区| 亚洲色图视频网| 欧美午夜精品久久久久久超碰| 性久久久久久久久久久| 狠狠色综合日日| 亚洲天堂福利av| 日韩欧美国产高清| 日本成人精品视频| 国产调教打屁股xxxx网站| 久久精品噜噜噜成人av农村| 国产精品夫妻自拍| 精品人妻中文无码av在线| 成人黄色小视频| 午夜伦欧美伦电影理论片| 国产视频一区二区三区在线观看| 女女互磨互喷水高潮les呻吟 | 波多野结衣有码| 国产老妇另类xxxxx| 亚洲最大的成人av| 国产人成亚洲第一网站在线播放| 在线观看不卡一区| 中文字幕av久久爽一区| 91社区在线播放| 久久机这里只有精品| 亚洲免费大片在线观看| 久久综合九色综合97婷婷女人| 在线观看一区不卡| 亚洲av熟女国产一区二区性色 | 欧美老女人在线| 国产亚洲精品精品精品| 一级全黄裸体片| 国产精品亚洲一区二区三区妖精| 亚洲高清免费观看| 国产精品女上位| 欧美变态口味重另类| 亚洲一区二区三区蜜桃| 91碰在线视频|