virtualization

brctl: network bridges

# create bridge
brctl addbr br0
ifconfig eth0 0.0.0.0

brctl delif lxcbr0 eth0
brctl addif br0 eth0
dhclient br0

# move VM to other bridge
for IF in $(brctl show | grep veth | sed 's/^[ \t]*//'); do
brctl delif lxcbr0 ${IF}
brctl addif br0 ${IF}
done

# connect two bridges?
ip link add veth0 type veth peer name veth1
ifconfig veth0 up
ifconfig veth1 up

brctl delif br0 veth0
brctl delif lxcbr0 veth1

# renew ip in VM
lxc-attach -n vm1 -- dhclient

# /etc/network/interfaces
auto eth0
iface eth0 inet manual

auto br0
iface br0 inet dhcp

Update LXC container templates filesystem

<?php
$URL="https://raw.githubusercontent.com/panticz/lxc/master/scripts/lxc-update-templates.sh";
echo "wget -q --no-check-certificate $URL -O - | bash -";
echo "

";
$c = curl_init();
curl_setopt($c, CURLOPT_URL, $URL);
curl_setopt($c, CURLOPT_RETURNTRANSFER, 1);
echo htmlspecialchars(curl_exec($c));
curl_close($c);
echo "

";
?>

# fix dns
echo "nameserver 8.8.8.8" > /var/cache/lxc/debian/rootfs-wheezy-amd64/etc/resolv.conf

Cronjob
echo "0 13 * * * root /usr/bin/wget -q --no-check-certificate https://raw.githubusercontent.com/panticz/lxc/master/scripts/lxc-update-templates.sh -O - | bash -" > /etc/cron.d/lxc_update_template
service cron restart

# fix squeeze repository
sed -i 's|cdn.debian.net|ftp.debian.org|g' /var/cache/lxc/debian/rootfs-squeeze-amd64/etc/apt/sources.list

Docker

Installation
https://docs.docker.com/install/linux/docker-ce/ubuntu/#set-up-the-repository
http://www.panticz.de/install-docker

Add user to docker group
sudo usermod -aG docker $USER
su - $USER

systemctl enable docker
systemctl status docker

Start all exited container
docker start $(docker ps -a -q -f status=exited)

Stop all containers
docker stop $(docker ps -a -q)

# Delete all containers
#docker stop $(docker ps -a -q)
docker rm $(docker ps -a -q) -f

# Delete all images

Install LXC (Linux Containers) under Ubuntu

Installation
apt install -y bridge-utils debootstrap lxc-templates lxc
http://www.panticz.de/install_lxc

Create container
export LANG=en_US.UTF-8
export CONTAINER=wheezy

sudo sudo lxc-destroy -n ${CONTAINER}
sudo lxc-create -t debian -n ${CONTAINER}
sudo lxc-start -d -n ${CONTAINER}

echo 'Acquire::http::Proxy "http://apt-cacher:3142/";' | sudo tee /var/lib/lxc/${CONTAINER}/rootfs/etc/apt/apt.conf

sudo lxc-attach -n ${CONTAINER} -- apt-get clean
sudo lxc-attach -n ${CONTAINER} -- apt-get update