Docker 单机网络
生活随笔
收集整理的這篇文章主要介紹了
Docker 单机网络
小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
?
Docker Network相關(guān)命令
root@ubuntu:~# docker network --helpUsage: docker network COMMANDManage networksOptions:Commands:connect Connect a container to a networkcreate Create a networkdisconnect Disconnect a container from a networkinspect Display detailed information on one or more networksls List networksprune Remove all unused networksrm Remove one or more networksRun 'docker network COMMAND --help' for more information on a command.?
查看所有已存在的Docker網(wǎng)絡(luò)
root@ubuntu:~# docker network ls NETWORK ID NAME DRIVER SCOPE 5f744cf3807c bridge bridge local c318b9c14c37 host host local 835478f79db9 my_network bridge local 3d1a9b1b894e my_network2 bridge local bee35f193006 none null local?
創(chuàng)建Docker網(wǎng)絡(luò)
?
root@ubuntu:~# docker network create --driver=bridge --subnet 192.168.0.0/24 --gateway 192.168.0.1 docker_network 00b5d16509dc3a7233b4e425ea3350d16f7a417d135039455d143f97dfc0d0bd?
?
檢驗(yàn)Docker網(wǎng)絡(luò)
root@ubuntu:~# docker network inspect docker_network [{"Name": "docker_network","Id": "00b5d16509dc3a7233b4e425ea3350d16f7a417d135039455d143f97dfc0d0bd","Created": "2018-03-15T22:09:38.385913404+08:00","Scope": "local","Driver": "bridge","EnableIPv6": false,"IPAM": {"Driver": "default","Options": {},"Config": [{"Subnet": "192.168.0.0/24","Gateway": "192.168.0.1"}]},"Internal": false,"Attachable": false,"Ingress": false,"ConfigFrom": {"Network": ""},"ConfigOnly": false,"Containers": {},"Options": {},"Labels": {}} ]?
將容器加入Docker網(wǎng)絡(luò)
root@ubuntu:~# docker run -it --network=docker_network busybox / # ip a 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue qlen 1link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00inet 127.0.0.1/8 scope host lovalid_lft forever preferred_lft forever 24: eth0@if25: <BROADCAST,MULTICAST,UP,LOWER_UP,M-DOWN> mtu 1500 qdisc noqueue link/ether 02:42:c0:a8:00:02 brd ff:ff:ff:ff:ff:ffinet 192.168.0.2/24 brd 192.168.0.255 scope global eth0valid_lft forever preferred_lft forever / #?
指定容器IP地址
root@ubuntu:~# docker run -it --network=docker_network --ip 192.168.0.10 busybox / # ip a 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue qlen 1link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00inet 127.0.0.1/8 scope host lovalid_lft forever preferred_lft forever 26: eth0@if27: <BROADCAST,MULTICAST,UP,LOWER_UP,M-DOWN> mtu 1500 qdisc noqueue link/ether 02:42:c0:a8:00:0a brd ff:ff:ff:ff:ff:ffinet 192.168.0.10/24 brd 192.168.0.255 scope global eth0valid_lft forever preferred_lft forever注:只有使用?--subnet?創(chuàng)建的網(wǎng)絡(luò)才能指定靜態(tài) IP。
?
Docker Network與Docker Network之間是不能通信的
root@ubuntu:~# iptables-save ... -A DOCKER-ISOLATION -i br-3d1a9b1b894e -o br-00b5d16509dc -j DROP -A DOCKER-ISOLATION -i br-00b5d16509dc -o br-3d1a9b1b894e -j DROP -A DOCKER-ISOLATION -i docker0 -o br-00b5d16509dc -j DROP -A DOCKER-ISOLATION -i br-00b5d16509dc -o docker0 -j DROP -A DOCKER-ISOLATION -i docker0 -o br-3d1a9b1b894e -j DROP -A DOCKER-ISOLATION -i br-3d1a9b1b894e -o docker0 -j DROP -A DOCKER-ISOLATION -j RETURN -A DOCKER-USER -j RETURN?
轉(zhuǎn)載于:https://www.cnblogs.com/vincenshen/p/8576995.html
總結(jié)
以上是生活随笔為你收集整理的Docker 单机网络的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: Linux下如何编译并运行C程序
- 下一篇: 让Web站点崩溃最常见的七大原因