LXD 3.0 Container with Container Commands

  • Use init instead of launch to create new container.
    lxc init ubuntu:18.04 c1
    
  • Attach network
lxc network attach lxdbr0 c1 eth0
  • Configure static IP
lxc stop c1
lxc network attach lxdfan0 c1 eth0 eth0
lxc config device set c1 eth0 ipv4.address 10.10.2.212
lxc start c1
  • Limit Disk size
lxc config device override <container> root size=20GB
  • Limit Memory Usage
lxc config set c1 limits.memory 100MB
  • Limit CPU Usage
lxc config set c1 limits.cpu 2

# only pin the 1st CPU. The second is 1-1. all is 0-2
lxc config set c1 limits.cpu 0-0

# limit cpu time 10%
lxc config set c1 limits.cpu.allowance 10ms/100ms
  • Limit Network
# Download
lxc config device set c1 eth0 limits.ingress 1Mbit

# Upload
lxc config device set c1 eth0 limits.egress 1Mbit

  • Port forwarding
# set container static ip first
lxc config device add ${CONTAINER_NAME} myport${HOST_PORT} proxy listen=tcp:${HOST_IP}:${HOST_PORT} connect=tcp:0.0.0.0:${CONTAINER_PORT} nat=true

  • Enable docker
    lxc config set docker01 security.nesting true
    lxc config set docker01 security.privileged true
    
  • Start docker
    lxc start c1
    

Reference:

https://stgraber.org/2016/10/27/network-management-with-lxd-2-3/

https://blog.ubuntu.com/2016/03/22/lxd-2-0-your-first-lxd-container

https://www.maketecheasier.com/limit-lxd-containers-resources/

Written on June 24, 2018