lxc.rst
changeset 2345 cb168a3d27ec
parent 2317 897bb1696e5f
child 2346 f644e8d27cd2
equal deleted inserted replaced
2344:8370ecc93eec 2345:cb168a3d27ec
    24 https://brauner.github.io/2018/02/27/lxc-removes-legacy-template-build-system.html
    24 https://brauner.github.io/2018/02/27/lxc-removes-legacy-template-build-system.html
    25   Details about replacing template stripts.
    25   Details about replacing template stripts.
    26 
    26 
    27 Install LXC under Debian
    27 Install LXC under Debian
    28 ========================
    28 ========================
    29 ::
       
    30 
    29 
    31   $ sudo apt-get install lxc
    30 Installation::
    32 
    31 
    33 Verify your host/kernel satisfy LXC requirements::
    32   $ sudo apt install lxc
       
    33 
       
    34 Verify that your host/kernel satisfies LXC requirements::
    34 
    35 
    35   $ sudo lxc-checkconfig
    36   $ sudo lxc-checkconfig
    36 
    37 
    37 To make network bridge install supplement packages::
    38 To make network bridge install supplement packages::
    38 
    39 
    40 
    41 
    41 To bootstrap Debian dostro into container install::
    42 To bootstrap Debian dostro into container install::
    42 
    43 
    43   $ sudo apt-get install debootstrap
    44   $ sudo apt-get install debootstrap
    44 
    45 
    45 To bring up network bridge edir ``/etc/default/lxc-net``::
    46 To bring up network bridge create or edit ``/etc/default/lxc-net``::
    46 
    47 
    47   USE_LXC_BRIDGE="true"
    48   USE_LXC_BRIDGE="true"
    48 
    49 
    49   LXC_ADDR="192.168.99.1"
    50   LXC_ADDR="10.0.0.1"
    50   LXC_NETMASK="255.255.255.0"
    51   LXC_NETMASK="255.255.255.0"
    51   LXC_NETWORK="192.168.99.1/24"
    52   LXC_NETWORK="10.0.0.0/24"
    52   LXC_DHCP_RANGE="192.168.99.100,192.168.99.200"
    53   LXC_DHCP_RANGE="10.0.0.2,10.0.0.254"
    53   LXC_DHCP_MAX="20"
    54   LXC_DHCP_MAX="253"
       
    55   LXC_DHCP_CONFILE=""
       
    56   LXC_DOMAIN=""
    54 
    57 
    55 and start service::
    58 and start service::
    56 
    59 
    57   $ sudo service lxc-net start
    60   $ sudo service lxc-net start
       
    61   $ sudo systemctl restart lxc-net.service
    58 
    62 
    59 Create new container in LXC
    63 Create new container in LXC
    60 ===========================
    64 ===========================
    61 
    65 
    62 Create container from template::
    66 Create container from template::
    87 options run::
    91 options run::
    88 
    92 
    89   $ /usr/share/lxc/templates/lxc-ubuntu -h
    93   $ /usr/share/lxc/templates/lxc-ubuntu -h
    90   $ /usr/share/lxc/templates/lxc-debian -h
    94   $ /usr/share/lxc/templates/lxc-debian -h
    91   $ /usr/share/lxc/templates/lxc-alpine -h
    95   $ /usr/share/lxc/templates/lxc-alpine -h
       
    96   $ /usr/share/lxc/templates/lxc-download -h
    92   ...
    97   ...
    93 
    98 
    94 For Debian in order to use another miror::
    99 For Debian in order to use another miror::
    95 
   100 
    96   $ MIRROR=http://httpredir.debian.org/debian sudo lxc-create -t debian -n debtest -- -r sid
   101   $ MIRROR=http://httpredir.debian.org/debian sudo lxc-create -t debian -n debtest -- -r sid
       
   102 
       
   103 List of prebuild containers:
       
   104 
       
   105 * Visit http://images.linuxcontainers.org/ (default storage of LXC project).
       
   106 * Run ``/usr/share/lxc/templates/lxc-download --list``
       
   107 
       
   108 Creating container by downloading pre-built image::
       
   109 
       
   110    sudo lxc-create -t download -n alpine-edge -- -d alpine -r edge -a amd64
       
   111    sudo lxc-create -t download -n debian-sid -- -d debian -r sid -a amd64
    97 
   112 
    98 Since LXC v3.0 sh-templates moved to separate project and only 4 are left supported::
   113 Since LXC v3.0 sh-templates moved to separate project and only 4 are left supported::
    99 
   114 
   100   $ lxc-create my-busybox -t busybox
   115   $ lxc-create my-busybox -t busybox
   101   $ lxc-create my-x -t download
   116   $ lxc-create my-x -t download
   141 
   156 
   142 Link containers in non standard location to take them in account::
   157 Link containers in non standard location to take them in account::
   143 
   158 
   144   $ ln -s /opt/lxc/$NAME /var/lib/lxc/$NAME
   159   $ ln -s /opt/lxc/$NAME /var/lib/lxc/$NAME
   145 
   160 
   146 Run command in rinning container::
   161 Run command in running container::
   147 
   162 
   148   $ sudo lxc-attach -n $NAME-get update
   163   $ sudo lxc-attach -n $NAME
       
   164   $ sudo lxc-attach -n $NAME bash
       
   165   $ sudo lxc-attach -n $NAME -- ls -a
       
   166   $ sudo lxc-attach -n $NAME -- apk list
   149 
   167 
   150 Making snapshot
   168 Making snapshot
   151 ===============
   169 ===============
   152 
   170 
   153 See ``lxc-snapshot(1)``.
   171 See ``lxc-snapshot(1)``.