Benutzer-Werkzeuge

Webseiten-Werkzeuge


lxc

Dies ist eine alte Version des Dokuments!


Linux Container (LXC) ist ein Verfahren zur Virtualisierung auf Betriebssystemebene, das mehrere voneinander isoliert laufende Linux Systeme in Containern auf einem einzigen Host ermöglicht.

Siehe auch 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/<container-name>/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
lxc.1762078954.txt.gz · Zuletzt geändert: 2025/11/02 11:22 von jango