LXD images and multiple hosts

Remote operations require the following two commands having been run on the remote server:

lxc config set core.https_address "[::]:8443"
lxc config set core.trust_password some-password

Add a remote server:

lxc remote add <server alias> <ip address or DNS>

And after that, use all the same command as above but prefixing the container and images name with the remote host like:

lxc exec host-a:first -- apt-get update

Manually import images example:

lxc image copy images:gentoo/current/amd64 local: --alias gentoo --auto-update
lxc image import <tarball> --alias random-image
lxc image import https://dl.stgraber.org/lxd --alias busybox-amd64

List images:

lxc image list
lxc image list <remote server alias>:

Editing image:

lxc image edit <alias or fingerprint>

Deleting image:

lxc image delete <alias or fingerprint>

Create you own image from a container:

lxc publish my-container/some-snapshot --alias some-image

 

 

Reference:
Installing LXD and the command line tool
LXD 2.0: Image management [5/12]

LXD Containers with Static IP Addresses

1. Edit /etc/default/lxd-bridge and change the value of LXC_CONFILE

$ sudo vi /etc/default/lxd-bridge
...
# Path to an extra dnsmasq configuration file
LXD_CONFILE="/etc/default/lxd_dnsmasq.conf"
...

2. Edit /etc/default/lxd_dnsmasq.conf and add container ip setting

$ sudo vi /etc/default/lxd_dnsmasq.conf
# dhcp-host=containername,ipaddress
dhcp-host=myc1,10.0.3.10

3. Stop container. restart lxd-bridge, start container

$ sudo lxc stop myc1
$ sudo service lxd-bridge stop && sudo service lxd-bridge start
$ sudo lxc start myc1

Reference:http://jason.trickett.us/2016/08/lxd-containers-static-ip-addresses-heres/

Using LXD on Ubuntu 16.04

1. install lxd

$ sudo apt install lxd

2. Enable swap accounting

$ sudo vi /etc/default/grub
GRUB_CMDLINE_LINUX_DEFAULT="swapaccount=1"
$ sudo update-grub
$ sudo shutdown -r now

3. create lxd user

$ sudo useradd -s /bin/bash -m lxdadm
$ sudo passwd lxdadm
$ sudo adduser lxdadm lxd

4. init lxd

$ sudo lxd init

5. Creating the first container

$ sudo su - lxdadm
$ newgrp lxd

// create container ubuntu16
$ lxc launch ubuntu:xenial ubuntu16

// list lxc containers
$ lxc list
$ lxc info ubuntu16

// open a shell in ubuntu16
$ lxc exec ubuntu16 bash

6. Create container without starting it

$ lxc init ubuntu:xenial ubuntu16

6. List images

$ lxc image list
$ lxc image list images:
$ lxc image list ubuntu:

7. List containers

$ lxc list
$ lxc list --fast
$ lxc info <container>

8. Start/stop a container

$ lxc start 
$ lxc stop <container>
$ lxc stop  <container> --force
$ lxc restart <containter>
$ lxc restart <container> --force
$ lxc pause <container>

9. Profiles

$ lxc profile list
$ lxc profile show <profile>
$ lxc profile edit <profile>
$ lxc profile apply <container> <profile1>,<profile2>,...

10. Shell

$ lxc exec <container> bash
$ lxc exec <container> -- ls -lh /
$ lxc exec <container> --env mykey=myvalue

11. Files

$ lxc file pull <container>/<path> <dest>
$ lxc file pull <container>/<path> - //read file to standard output
$ lxc file push <source> <container>/<path>
$ lxc file edit <container>/<path>

11. Snapshot

$ lxc snapshot <container>
$ lxc snapshot <container> <snapshot name>
$ lxc info <container> //see snapshot
$ lxc restore <container> <snapshot name>
$ lxc move <container>/<snapshot name> <container>/<new snapshot name>
$ lxc delete <container>/<snapshot name>

12. Cloning/renaming/delting

$ lxc copy <source container> <destination container> 
$ lxc move <old name> <new name>  
$ lxc delete <container>

13. CPU limit

$ lxc config set my-container limits.cpu 2  //any 2 cpus

$ lxc config set my-container limits.cpu 1,3 // cpu #2 #4

$ lxc config set my-container limits.cpu 0-3,7-11

$ lxc config set my-container limits.cpu.allowance 10% // limit time 10% of total

$ lxc config set my-container limits.cpu.priority 0

14. Memory limit

$ lxc config set my-container limits.memory 256MB

15. Disk limit (requires btrfs or ZFS)

$ lxc config device set my-container root size 20GB

16. IO reading/writing limits

$ lxc config device set my-container root limits.read 20Iops
$ lxc config device set my-container root limits.write 10Iops

17. Autostart container

$ lxc config set container_name boot.autostart 1

18. Mount host directory

$ lxc config device add container_name device_name disk source=host_directory path=guest_directory