This is what I use on a Mint 17 Xfce Web Development Workstation, that will use local DNS support for .lxc Container Names.
lts14
as the LVM Volume Group, with the following Volumes:/
← the file system root directory/home
← the user home directorieslts14
has the necessary free or unused space to do that.
$ sudo lvcreate -L 100G -n lxc lts14 $ sudo lvcreate -L 100G -n lxcsnap lts14 $ sudo mkfs -t ext4 /dev/mapper/lts14-lxc $ sudo mkfs -t ext4 /dev/mapper/lts14-lxcsnap
$ sudo mkdir /var/lib/lxc $ sudo mkdir /var/lib/lxcsnaps $ sudo nano /etc/fstab # add the following lines to this file
/dev/mapper/lts14-lxc /var/lib/lxc ext4 defaults 0 2 /dev/mapper/lts14-lxcsnap /var/lib/lxcsnaps ext4 defaults 0 2
RESTART SYSTEM
$ sudo apt-get install lxc lxctl lxc-templates debootstrap yum cloud-utils qemu-user-static
debootstrap
← needed for templates that download .deb files to install – such as the ubuntu templateyum
← needed by .rpm base linux distributions – Oracle Linux is the example used below.cloud-utils
← needed to install the ubuntu-cloud templateqemu-user-static
← to run containers of non-native architectures – eg. ARM (-a armhf)lts14
for Ubuntu 14.04LTS, and lts12
for Ubuntu 12.04LTS.) Replace [password]
in the below command lines with a password of your choice. (For the Ubuntu template, the default username & password is ubuntu
& ubuntu
.)
$ sudo su # lxc-create -n ubuntu14lts -t ubuntu -- -a amd64 -r trusty --user lts14 --password [password] # lxc-create -n ubuntu12lts -t ubuntu -- -a amd64 -r precise --user lts12 --password [password] # lxc-create -n oracle -t oracle # an RPM base Linux Distro/Container # exit
$ sudo apt-get install dnsmasq
$ sudo nano /etc/dnsmasq.d-available/lxc # add the following @ bottom of this file
# Add the IP address for .lxc DNS resolution here. server=/lxc/10.0.3.1
$ sudo nano /etc/default/lxc-net
… In this file, remove the leading # to UNCOMMENT the following line ⇒ LXC_DOMAIN=“lxc”
Note: It is possible to use a Linux Container (e.g. vpn.lxc) to access a VPN network. (I'm still working through how to do that.)
Other References:
clear-on-reload
$ sudo lxc-start -n ubuntu14lts -d # start ubmutu14lts container in the background $ sudo lxc-info -n ubuntu14lts # example output below:
Name: ubuntu14lts State: RUNNING PID: 7463 IP: 10.0.3.249 CPU use: 2.31 seconds BlkIO use: 40.86 MiB Memory use: 27.78 MiB Link: vethRFW7N4 TX bytes: 2.15 KiB RX bytes: 6.29 KiB Total bytes: 8.44 KiB
$ ping ubuntu14lts.lxc # example output below:
PING ubuntu14lts.lxc (10.0.3.249) 56(84) bytes of data. 64 bytes from 10.0.3.249: icmp_seq=1 ttl=64 time=0.052 ms 64 bytes from 10.0.3.249: icmp_seq=2 ttl=64 time=0.069 ms 64 bytes from 10.0.3.249: icmp_seq=3 ttl=64 time=0.065 ms 64 bytes from 10.0.3.249: icmp_seq=4 ttl=64 time=0.065 ms 64 bytes from 10.0.3.249: icmp_seq=5 ttl=64 time=0.067 ms 64 bytes from 10.0.3.249: icmp_seq=6 ttl=64 time=0.069 ms 64 bytes from 10.0.3.249: icmp_seq=7 ttl=64 time=0.070 ms 64 bytes from 10.0.3.249: icmp_seq=8 ttl=64 time=0.068 ms 64 bytes from 10.0.3.249: icmp_seq=9 ttl=64 time=0.066 ms ^C --- ubuntu14lts.lxc ping statistics --- 9 packets transmitted, 9 received, 0% packet loss, time 7999ms rtt min/avg/max/mdev = 0.052/0.065/0.070/0.010 ms
$ sudo lxc-stop -n ubuntu14lts # shutdown ubuntu14lts container