April 21, 2016
Quick & Easy: LXC Container on Ubuntu 16.04
Install lxc
apt-get install lxc -y
create container with latest ubuntu
sudo lxc-create -n loki -t ubuntu
create container with ubuntu 14.04
sudo lxc-create -t download -n loki -- -d ubuntu -r trusty -a amd64
start container
sudo lxc-start -n loki
login to container
sudo lxc-attach -n loki
or you can run
sudo lxc-create -n loki -t ubuntu && lxc-start -n loki && lxc-attach -n loki
run a test with caddy http server
apt-get install curl ca-certificates -y
curl https://getcaddy.com | bash
mkdir -p /var/www
echo "#woah ninja#" > /var/www/index.md
caddy -root "/var/www/" "markdown" "tls self_signed" &
logout
exit
find ip of container
sudo lxc-info -n loki
check if port is open on container
nc -zv loki-ip 2015
setup forwarding manually
sysctl net.ipv4.ip_forward=1
iptables -t nat -A PREROUTING -p tcp -d host-ip --dport 2015 -j DNAT --to-destination loki-ip:2015
iptables -t nat -A POSTROUTING -j MASQUERADE
Distroy container
lxc-destroy -n loki
sources:unixmen, Arch, do, cyberciti