meta data for this page
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
linux:docker:network [2019/09/23 12:19] – niziak | linux:docker:network [2020/03/20 20:13] (current) – niziak | ||
---|---|---|---|
Line 1: | Line 1: | ||
+ | ====== Networking ====== | ||
+ | |||
+ | [[https:// | ||
+ | |||
+ | In default docker networking: | ||
+ | * traffic from container to world is NATed. | ||
+ | * incoming traffic for mapped port is handled by '' | ||
+ | |||
+ | ===== Setup default subnet for containers ===== | ||
+ | |||
+ | By default docker try to choose not conflicting addressing scheme: | ||
+ | < | ||
+ | |||
+ | but sometimes it doesn' | ||
+ | |||
+ | <file json | / | ||
+ | { | ||
+ | " | ||
+ | [ | ||
+ | {" | ||
+ | ] | ||
+ | } | ||
+ | </ | ||
+ | Will assign 16 bit class for docker daemon, and docker daemon will create 24 bit network per each network. | ||
+ | |||
+ | |||
+ | Another example: | ||
+ | <file json | / | ||
+ | { | ||
+ | " | ||
+ | " | ||
+ | {" | ||
+ | {" | ||
+ | ] | ||
+ | } | ||
+ | </ | ||
+ | ====== How to connect container to real network ====== | ||
+ | |||
+ | Idea is, how to start multiple containers, serving different services on the same port, but different IP. | ||
+ | Similar to use bridged network with VirtualBox. | ||
+ | |||
+ | |||
[[http:// | [[http:// | ||
[[http:// | [[http:// | ||
- | ====== Linux Kernel drivers | + | ===== Use IP alias ===== |
+ | Simply add additional IP to one of host network interfaces. Then use port mapping to host IP:port during Docker start. | ||
+ | **PROBLEM: | ||
+ | |||
+ | ===== Host DNAT ===== | ||
+ | NOT TESTED. | ||
+ | * Use IP alias like above. | ||
+ | * Use Docker container in classic ways - expose container services on non conflicting host ports. | ||
+ | * Use iptables with DNAT to redirect traffic to given IP:port to container exposed port. | ||
+ | * Use iptables with SNAT to set correct originating address | ||
+ | |||
+ | ===== Use real host bridge ===== | ||
+ | |||
+ | Set docker internal bridge name to real one on host. | ||
+ | NOTE: Docker will manipulate host bridge (assign configured address!) | ||
+ | [[https:// | ||
+ | |||
+ | |||
+ | ===== Connect docker bridge with real host bridge ===== | ||
+ | |||
+ | Reference: [[https:// | ||
+ | |||
+ | Create virtual adapter pair: | ||
+ | <code bash>ip link add dev veth_docker_lan type veth peer name veth_br-lan</ | ||
+ | |||
+ | Add each adapter to one of bridges: | ||
+ | <code bash> | ||
+ | brctl addif docker_lan veth_docker_lan | ||
+ | ip link set veth_docker_lan up | ||
+ | |||
+ | brctl addif br-lan veth_br-lan | ||
+ | ip link set veth_br-lan up | ||
+ | </ | ||
+ | |||
+ | ISSUES: In theory it works, but problem with itpables and routing. Conntrack cannot see packets (different NS ?), so all packets are treated as INVALID on firewall. | ||
+ | |||
+ | |||
+ | From [[https:// | ||
+ | Before MACVLAN, if you wanted to connect to physical network from a VM or namespace, you would have needed to create TAP/VETH devices and attach one side to a bridge and attach a physical interface to the bridge on the host at the same time, as shown below. | ||
+ | Now, with MACVLAN, you can bind a physical interface that is associated with a MACVLAN directly to namespaces, without the need for a bridge. | ||
+ | |||
+ | ===== MACVLAN & IPVLAN ===== | ||
+ | |||
+ | ==== Linux Kernel drivers ==== | ||
* **bridge** - gives connectivity between endpoints, but external access requires NAT | * **bridge** - gives connectivity between endpoints, but external access requires NAT | ||
Line 21: | Line 106: | ||
* Autoconfigured EUI-64 IPv6 addresses are based on MAC address. All VMs or containers sharing the same parent interface will auto-generate the same IPv6 address. Ensure that your VMs or containers use static IPv6 addresses or IPv6 privacy addresses and disable SLAAC. | * Autoconfigured EUI-64 IPv6 addresses are based on MAC address. All VMs or containers sharing the same parent interface will auto-generate the same IPv6 address. Ensure that your VMs or containers use static IPv6 addresses or IPv6 privacy addresses and disable SLAAC. | ||
- | ===== macvlan details | + | **NOTE**: Both modes requires support from HW to use multiple MAC. Without it device needs to be switched into promiscuous mode, which is not easy. Working methods: |
+ | * Virtualbox on host machine - during host machine startup it sets own driver | ||
+ | |||
+ | ==== macvlan details ==== | ||
[[https:// | [[https:// | ||
Line 31: | Line 119: | ||
* **passtrhru** - assign real physical interface for single VM (and gives full controll to interface) | * **passtrhru** - assign real physical interface for single VM (and gives full controll to interface) | ||
+ | Issue with bridge: | ||
+ | * macvlan0 added to host bridge works bad. It doesn' | ||
- | + | * https:// | |
- | ===== macvlan example | + | ==== macvlan example ==== |
There can be only one macvlan network with the same subnet and gateway. So better is to create network manually: | There can be only one macvlan network with the same subnet and gateway. So better is to create network manually: | ||
Line 64: | Line 154: | ||
<code bash> | <code bash> | ||
- | ===== communication with host ===== | + | ==== communication with host ==== |
Linux Macvlan interface types are not able to ping or communicate with the default namespace IP address. | Linux Macvlan interface types are not able to ping or communicate with the default namespace IP address. | ||
For example, if you create a container and try to ping the Docker host's eth0 it will not work. | For example, if you create a container and try to ping the Docker host's eth0 it will not work. | ||
Line 98: | Line 188: | ||
- | ===== communication from containers to macvlan container | + | ==== communication from containers to macvlan container ==== |
Problem: containers with default network settings (172.22.0.0) cannot communicate with 192.168.0.242 | Problem: containers with default network settings (172.22.0.0) cannot communicate with 192.168.0.242 | ||
Line 118: | Line 208: | ||
- | + | === openvpn === | |
- | ==== openvpn | + | |
After above fixes, there is traffic from docker 192.168.0.242 to host 192.168.0.231 and vice versa. | After above fixes, there is traffic from docker 192.168.0.242 to host 192.168.0.231 and vice versa. |