Linux Container


Installation


sudo apt-get install lxc
sudo systemctl status lxc
sudo snap install lx
sudo apt install lxd lxd-client

sudo systemctl start lxd
sudo systemctl status lxd
    

Initialization

After sudo lxd init,


Would you like to use LXD clustering? (yes/no) [default=no]: 
Do you want to configure a new storage pool? (yes/no) [default=yes]: 
Name of the new storage pool [default=default]: 
Would you like to connect to a MAAS server? (yes/no) [default=no]: 
Would you like to create a new local network bridge? (yes/no) [default=yes]: 
What should the new bridge be called? [default=lxdbr0]: 
What IPv4 address should be used? (CIDR subnet notation, “auto” or “none”) [default=auto]: 
What IPv6 address should be used? (CIDR subnet notation, “auto” or “none”) [default=auto]: 
Would you like LXD to be available over the network? (yes/no) [default=no]: 
Would you like stale cached images to be updated automatically? (yes/no) [default=yes] 
    

Clustering means multiple computer server. Local network bridge allows the containers to communicate with the original computer. All of them are default. Storage backend to dir. Stale cached images updated automatically ensure the remote repo updates your local images whenever there are changes.

Instructions

The followings are for understanding your system,


sudo lxc help # find the command
sudo lxc version # just print version == 3
sudo lxc storage list # where to store lxc
sudo lxc info a
lxc config show a
lxc profile list
lxc profile show default
sudo lxc remote list # which repo to install lxc
sudo lxc image list # what is downloaded
sudo lxc image list images: # list all images that can be downloaded
sudo lxc image list images:ubuntu
sudo lxc image list # list all running containers
uname -r # 5.4.0-66-generic host kernel
lsb_release -dirc # show version
free -m # show ram
ip a s # show all connections like inet
nproc # number of processors
hostname # yui@yui-Inspiron-7590 will show yui-Inspiron-7590
ping lxname.lxd
    
Operations
  1. Launch an instance.
  2. 
    lxc launch ubuntu:16.04
        
  3. Sometimes it can cause an error, like LXD does not have a uid/gid allocation.
  4. Add root:100000:65536 to /etc/subuid and /etc/subgid, then reboot.
  5. ip a s or ifconfig can show the new network bridge.
  6. Delete container by,
  7. 
    lxc stop prepared-snipe # also have start option
    lxc delete prepared-snipe # --force without stopping
        
  8. Copy the instance.
  9. 
    lxc copy a b
    lxc start b
        
  10. Rename the instance.
  11. 
    lxc stop a
    lxc move a c
    lxc start c
        
  12. Log into the instance.
  13. 
    lxc exec a bash # login as a root user
        
  14. Use exit to get out.
  15. Limit resources, options: memory, cpu
  16. 
    lxc config set a limits.memory 512MB # or 1GB , check out by free -m 
    OR in profile
    lxc profile edit profilename # config: limits.memory: 512MB
    lxc launch ubuntu:16.04 env2 --profile profilename
        
  17. Send files,
  18. 
    lxc file push filename containername/root/
    lxc file pull containername/root/filename .
        
  19. Backup container
  20. 
    lxc snapshot a backupname
    lxc restore a backupname
        

    

References


  1. Linux containers LXC -- Getting Started
  2. Youtube -- Getting started with LXC containers
  3. Newbie question: what’s the lxc version of a Dockerfile?