MoinMoin Logo
  • Comments
  • Immutable Page
  • Menu
    • Navigation
    • RecentChanges
    • FindPage
    • Local Site Map
    • Help
    • HelpContents
    • HelpOnMoinWikiSyntax
    • Display
    • Attachments
    • Info
    • Raw Text
    • Print View
    • Edit
    • Load
    • Save
  • Login

Navigation

  • Start
  • Sitemap
Revision 17 as of 2022-06-12 18:34:59
  • lxc

lxc

Linux Containers

  • https://linuxcontainers.org/lxc/introduction/

  • http://www.cyberciti.biz/faq/how-to-create-unprivileged-linux-containers-on-ubuntu-linux/

  • http://en.wikipedia.org/wiki/LXC

LXC (Linux Containers) is an operating system–level virtualization method for running multiple isolated Linux systems (containers) on a single control host.

LXC provides operating system-level virtualization through a virtual environment that has its own process and network space, instead of creating a full-fledged virtual machine.

Ubuntu precise i386 container on Slackware 14.2

   1 2016-11-08T23:39 root@nb200:/tmp
   2 $ lxc-create -t download -n containerx -- -d ubuntu  -r precise -a i386
   3 Setting up the GPG keyring
   4 Downloading the image index
   5 Downloading the rootfs
   6 Downloading the metadata
   7 The image cache is now ready
   8 Unpacking the rootfs
   9 
  10 ---
  11 You just created an Ubuntu container (release=precise, arch=i386, variant=default)
  12 
  13 To enable sshd, run: apt-get install openssh-server
  14 
  15 For security reason, container images ship without user accounts
  16 and without a root password.
  17 
  18 Use lxc-attach or chroot directly into the rootfs to set a root password
  19 or create user accounts.
  20 # start a container
  21 lxc-start -n containerx -d
  22 # list containers
  23 lxc-ls --fancy
  24 # spawn a new shell running inside an existing container
  25 lxc-attach -n containerx
  26 
  27 # session in containerx 
  28 root@containerx:/etc# cat /etc/os-release 
  29 NAME="Ubuntu"
  30 VERSION="12.04.5 LTS, Precise Pangolin"
  31 ID=ubuntu
  32 ID_LIKE=debian
  33 PRETTY_NAME="Ubuntu precise (12.04.5 LTS)"
  34 VERSION_ID="12.04"
  35 
  36 # run several commands in the container
  37 lxc-attach -n containerx -- sh -c 'TESTFILE=/tmp/asd;cat $TESTFILE; echo $TESTFILE'
  38 lxc-attach -n containerx -- sh -c 'cat /etc/os-release; dpkg -l;'
  39 # containers are stored under  /var/lib/lxc/
  40 

Containers in Slackware64 15.0

  • https://linuxcontainers.org/lxc/manpages/man5/lxc.container.conf.5.html

  • https://docs.slackware.com/howtos:misc:lxc

   1 su
   2 # list available templates and distros
   3 lxc-create -t download -n NAME
   4 #Setting up the GPG keyring
   5 #Downloading the image index
   6 #
   7 #---
   8 #DIST   RELEASE ARCH    VARIANT BUILD
   9 #---
  10 #almalinux      8       amd64   default 20220224_23:09
  11 #almalinux      8       arm64   default 20220224_23:09
  12 #alpine 3.12    amd64   default 20220225_13:00
  13 #alpine 3.12    arm64   default 20220225_13:01
  14 #alpine 3.12    armhf   default 20220225_13:00
  15 #alpine 3.12    i386    default 20220225_13:01
  16 # press ctrl+c to exit
  17 lxc-create -t download -n containery -- -d ubuntu  -r bionic -a i386
  18 lxc-start -n containery -d
  19 lxc-ls --fancy
  20 lxc-attach -n containery
  21 # in the container
  22 lsb_release -a

/etc/cgconfig.conf

group qwerty {
    perm {
        task {
            uid = vitor;
            gid = users;
        }
    admin {
          uid = vitor;
          gid = users;
      }
  }

  cpuset {
      cgroup.clone_children = 1;
      cpuset.mems = 0;
  }
  cpu {}
  cpuacct {}
  blkio {}
  memory { memory.use_hierarchy = 1; }
  devices {}
  freezer {}
  net_cls {}
  perf_event {}
  net_prio {}
  pids {}
}

/etc/cgrules.conf

vitor           *               qwerty/

/etc/subgid

vitor:100000:65537

/etc/subuid

vitor:100000:65537

/etc/default/lxc-net

   1 USE_LXC_BRIDGE="true"

/etc/lxc/default.conf

lxc.net.0.type = empty

~/.config/lxc/default.conf

lxc.idmap = u 0 100000 65536
lxc.idmap = g 0 100000 65536

lxc.net.0.type = veth
lxc.net.0.flags = up
lxc.net.0.link = lxcbr0

/etc/rc.d/rc.inet1.conf

   1 USE_DHCP[0]="yes"

/etc/rc.d/rc.local

   1 echo 1 > /proc/sys/net/ipv4/ip_forward
   2 /sbin/brctl addbr lxcbr0
   3 /sbin/brctl setfd lxcbr0 0
   4 /sbin/ifconfig lxcbr0 192.168.100.1 netmask 255.255.255.0 promisc up
   5 #/usr/sbin/iptables -t nat -A POSTROUTING -o wlan0 -j MASQUERADE
   6 /usr/sbin/iptables -t nat -A POSTROUTING -o wlan1 -j MASQUERADE
   7 /usr/libexec/lxc/lxc-net start

Test steps

   1 lxc-create -t download -n containery -- -d alpine  -r 3.16 -a i386
   2 lxc-start -n containery -d
   3 lxc-ls --fancy
   4 lxc-attach -n containery
   5 # commands inside container
   6 ping 8.8.8.8
   7 exit
   8 lxc-stop containery
   9 lxc-destroy containery 
  • MoinMoin Powered
  • Python Powered
  • GPL licensed
  • Valid HTML 4.01