**Linux Container** (LXC) ist ein Verfahren zur [[virtualisierung|Virtualisierung]] auf Betriebssystemebene, das mehrere voneinander isoliert laufende [[linux|Linux]] Systeme in [[container|Containern]] auf einem einzigen Host ermöglicht. Siehe auch [[docker|Docker]]. # Installation sudo apt install lxc # Interactive sudo lxc-create -t download -n my-ubuntu-template -- # One Liner sudo lxc-create -t download -n my-ubuntu-template -- --dist ubuntu --release focal --arch amd64 # Wird der GPG Key nicht gefunden sudo lxc-create -t download -n my-ubuntu-template -- --dist ubuntu --release focal --arch amd64 --no-validate # Liste Container sudo lxc-ls --fancy # Starte Container lxc-start --name my-ubuntu-template # Zeige Infos sudo lxc-info --name my-ubuntu-template # Auf Container verbinden sudo lxc-attach --name my-ubuntu-template # Container stoppen sudo lxc-stop --name my-ubuntu-template # Container löschen sudo lxc-destroy --name my-ubuntu-template =====Container Konfiguration===== Die Konfiguration für Container befindet sich unter /var/lib/lxc//config # Template used to create this container: /usr/share/lxc/templates/lxc-download # Parameters passed to the template: --dist ubuntu --release focal --arch amd64 --no-validate # Template script checksum (SHA-1): 273c51343604eb85f7e294c8da0a5eb769d648f3 # For additional config options, please look at lxc.container.conf(5) # Uncomment the following line to support nesting containers: #lxc.include = /usr/share/lxc/config/nesting.conf # (Be aware this has security implications) # Distribution configuration lxc.include = /usr/share/lxc/config/common.conf lxc.arch = linux64 # Container specific configuration lxc.rootfs.path = dir:/var/lib/lxc/my-ubuntu-template/rootfs lxc.uts.name = my-ubuntu-template lxc.mount.entry = /shared/data shared/data none bind,create=dir 0 0 # Network configuration lxc.net.0.type = veth lxc.net.0.link = lxcbr0 lxc.net.0.flags = up lxc.net.0.hwaddr = 00:16:3e:0d:15:2c =====Fake Docker===== ip link add name lxcbr0 type bridge ip addr add 10.0.3.1/24 dev lxcbr0 ip link set lxcbr0 up LXC Container an Bridge lxc.net.0.type = veth lxc.net.0.link = lxcbr0 lxc.net.0.flags = up lxc.net.0.hwaddr = 00:16:3e:xx:xx:xx [[DHCP]] optional dnsmasq --interface=lxcbr0 --bind-interfaces --dhcp-range=10.0.3.100,10.0.3.200,12h [[NAT]] iptables -t nat -A POSTROUTING -s 10.0.3.0/24 ! -o lxcbr0 -j MASQUERADE echo 1 > /proc/sys/net/ipv4/ip_forward Portweiterleitung iptables -t nat -A PREROUTING -p tcp --dport 8080 -j DNAT --to-destination 10.0.3.101:80 =====Networking===== ====Host Network==== * Der Container nutzt direkt das Netzwerk des Hosts. * Keine eigene IP – Container teilt sich die IP mit dem Host. * Vorteil: einfache Kommunikation mit anderen Diensten auf dem Host. * Nachteil: keine Isolation auf Netzwerkebene. lxc.network.type = none lxc.network.link = lxcbr0 lxc.network.flags = up lxc.network.mode = host ====MAC Vlan==== * Container bekommt eine eigene IP im gleichen physischen Netzwerk wie der Host. * Host und Container können sich nicht direkt pingen (außer mit zusätzlicher Bridge). * Vorteil: Container erscheint wie ein eigenes Gerät im Netzwerk. * Nachteil: eingeschränkte Kommunikation mit dem Host. lxc.net.0.type = macvlan lxc.net.0.link = eth0 lxc.net.0.flags = up lxc.net.0.hwaddr = 00:16:3e:xx:xx:xx =====Links===== * [[https://linuxcontainers.org/lxc/getting-started/|Linux Container - Getting Started]] * [[https://www.redhat.com/de/topics/containers/whats-a-linux-container|Linux Container - Red Hat]]