apt-get install -y lxc libvirt-bin
Mount the cgroup:
vim /etc/fstab cgroup /sys/fs/cgroup cgroup defaults 0 0 mount /sys/fs/cgroup
Make available live-debconfig package to taken by Debian Wheezy containers:
echo "deb http://ftp.de.debian.org/debian unstable main contrib non-free" > /etc/apt/sources.list.d/live-debconfig.list apt-get update cd /usr/share/lxc/packages apt-get download live-debconfig rm /etc/apt/sources.list.d/live-debconfig.list apt-get update
Mark default Network to autostart:
virsh net-autostart default
and start it:
virsh net-start default
Run these commands and read output:
mount cgroup on /sys/fs/cgroup type cgroup (rw,relatime,perf_event,blkio,net_cls,freezer,devices,cpuacct,cpu,cpuset)
virsh net-info default ip addr show virbr0
lxc-checkconfig
Command:
lxc-create -n nombrecontainer -t debian
Add to /var/lib/lxc/nombrecontainer/config
## Network lxc.network.type = veth lxc.network.flags = up # Network host side lxc.network.link = virbr0 # MUST BE UNIQUE FOR EACH CONTAINER lxc.network.veth.pair = veth0 lxc.network.hwaddr = 00:FF:AA:00:00:01 # Network container side lxc.network.name = eth0 lxc.network.ipv4 = 0.0.0.0/24
lxc-start -n nombrecontainer -d
lxc-console -n nombrecontainer
Type <Ctrl+a q> to exit the console
At /var/lib/libvirt/network/default.xml
configure fix IP address to each container's MAC address:
<dhcp> <range start="192.168.122.201" end="192.168.122.254" /> <host mac="00:FF:AA:00:00:01" name="foo.example.com" ip="192.168.122.101" /> <host mac="00:FF:AA:00:00:02" name="bar.example.com" ip="192.168.122.102" /> </dhcp>
los pasos siguientes hace que los contenedores pierdan la red
virsh net-destroy default
virsh net-start default
All services are access by just one IP address then same service into different container requires different public port
iptables -t nat -A PREROUTING -p tcp --dport 1022 -j DNAT --to 192.168.122.101:22
iptables -t nat -A PREROUTING -p tcp --dport 80 -j DNAT --to 192.168.122.102