This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| kvm_and_docker_on_one_host [2019/07/26 13:59] – herwarth | kvm_and_docker_on_one_host [2020/04/12 09:10] (current) – [ZFS] herwarth | ||
|---|---|---|---|
| Line 79: | Line 79: | ||
| systemctl enable libvirtd | systemctl enable libvirtd | ||
| =====Configure===== | =====Configure===== | ||
| + | ====Network==== | ||
| Because we already have the bridges created with netplan, we only need to assign them to networking names in libvirt. | Because we already have the bridges created with netplan, we only need to assign them to networking names in libvirt. | ||
| <code - / | <code - / | ||
| Line 135: | Line 136: | ||
| | | ||
| </ | </ | ||
| + | ====Systemd==== | ||
| + | Because we are going to use Docker with the same bridges, we have to wait for libvirt to start after Docker is started. Else the bridges are not available and autostart of VMs will fail. | ||
| + | < | ||
| + | cd / | ||
| + | rm libvirt-bin.service | ||
| + | cp / | ||
| + | vi libvirtd.service | ||
| + | </ | ||
| + | <code - / | ||
| + | . | ||
| + | . | ||
| + | . | ||
| + | After=network.target | ||
| + | After=dbus.service | ||
| + | After=iscsid.service | ||
| + | After=apparmor.service | ||
| + | After=local-fs.target | ||
| + | After=remote-fs.target | ||
| + | After=systemd-machined.service | ||
| + | After=docker.service | ||
| + | Documentation=man: | ||
| + | Documentation=https:// | ||
| + | |||
| + | [Service] | ||
| + | . | ||
| + | . | ||
| + | . | ||
| + | </ | ||
| + | Now we need to reload systemd | ||
| + | systemctl daemon-reload | ||
| + | |||
| ======Docker====== | ======Docker====== | ||
| =====Installation===== | =====Installation===== | ||
| apt install docker.io | apt install docker.io | ||
| systemctl enable docker | systemctl enable docker | ||
| + | We need docker-compose and are going to install it via pip | ||
| + | apt install python3-pip | ||
| + | Now install docker-compose | ||
| + | pip3 install docker-compose | ||
| + | | ||
| =====Configure===== | =====Configure===== | ||
| Docker is using iptables to mitigate traffic between containers. Because we are using VLANs with bridges, we do not want Docker to intervene network traffic. | Docker is using iptables to mitigate traffic between containers. Because we are using VLANs with bridges, we do not want Docker to intervene network traffic. | ||
| Line 146: | Line 183: | ||
| } | } | ||
| </ | </ | ||
| - | | + | When we stop docker to manipulate iptables it will not add the masquerade rule to the docker0 bridge. We need this iptables rule to make docker build work again. So first we are going to add the iptables rule manually. Find out which subnet is connected to docker0 |
| + | |||
| + | ip a s docker0 | ||
| + | < | ||
| + | 11: docker0: < | ||
| + | link/ether 02: | ||
| + | inet 172.17.0.1/ | ||
| + | | ||
| + | inet6 fe80:: | ||
| + | | ||
| + | </ | ||
| + | In this case the subnet is 172.17.0.0/ | ||
| + | iptables -t nat -A POSTROUTING -s 172.17.0.0/ | ||
| + | |||
| + | Now we have the rule added. Make it persistent. First install iptables-persistent | ||
| + | apt install iptables-persistent | ||
| + | It will tell you it created rules in: / | ||
| + | Check the rules.v4 file for the masquerade rule | ||
| + | |||
| + | cat / | ||
| + | < | ||
| + | # Generated by iptables-save v1.6.1 on Fri Jul 26 18:19:47 2019 | ||
| + | *nat | ||
| + | :PREROUTING ACCEPT [468: | ||
| + | :INPUT ACCEPT [22: | ||
| + | :OUTPUT ACCEPT [8:601] | ||
| + | : | ||
| + | -A POSTROUTING -s 172.17.0.0/ | ||
| + | COMMIT | ||
| + | # Completed on Fri Jul 26 18:19:47 2019 | ||
| + | # Generated by iptables-save v1.6.1 on Fri Jul 26 18:19:47 2019 | ||
| + | *filter | ||
| + | :INPUT ACCEPT [2328: | ||
| + | :FORWARD ACCEPT [3836: | ||
| + | :OUTPUT ACCEPT [1473: | ||
| + | : | ||
| + | -A FORWARD -j DOCKER-USER | ||
| + | -A DOCKER-USER -j RETURN | ||
| + | COMMIT | ||
| + | # Completed on Fri Jul 26 18:19:47 2019 | ||
| + | </ | ||
| + | ====ZFS==== | ||
| + | When you have a ZFS pool you want to use for storage | ||
| + | < | ||
| + | systemctl | ||
| + | rm -rf / | ||
| + | zfs create -o mountpoint=/ | ||
| + | </ | ||
| + | <code - / | ||
| + | { | ||
| + | " | ||
| + | " | ||
| + | } | ||
| + | </ | ||
| + | < | ||
| + | systemctl start docker | ||
| + | </ | ||
| + | Check with docker info | ||
| + | < | ||
| + | < | ||
| + | Client: | ||
| + | Debug Mode: false | ||
| + | |||
| + | Server: | ||
| + | | ||
| + | Running: 0 | ||
| + | Paused: 0 | ||
| + | Stopped: 0 | ||
| + | | ||
| + | | ||
| + | | ||
| + | Zpool: data | ||
| + | Zpool Health: ONLINE | ||
| + | Parent Dataset: data/docker | ||
| + | Space Used By Parent: 98304 | ||
| + | Space Available: 965292744704 | ||
| + | Parent Quota: no | ||
| + | Compression: | ||
| + | . | ||
| + | . | ||
| + | . | ||
| + | </ | ||
| ====Networks==== | ====Networks==== | ||
| In our example we are not going to use containers in the routed subnet bridge called internet | In our example we are not going to use containers in the routed subnet bridge called internet | ||
| Line 158: | Line 276: | ||
| docker network create -d macvlan --subnet=x.x.2.0/ | docker network create -d macvlan --subnet=x.x.2.0/ | ||
| </ | </ | ||
| + | Check it | ||
| + | docker network ls | ||
| + | < | ||
| + | NETWORK ID NAME DRIVER | ||
| + | 6ae8a5b99638 | ||
| + | 700edcbcc28b | ||
| + | 06d5b0706837 | ||
| + | cb04700d3481 | ||
| + | b0bdff0a6d53 | ||
| + | 320e38274915 | ||
| + | </ | ||
| + | |||
| + | {{tag> | ||