User Tools

Site Tools


lxc:install_lxc

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
lxc:install_lxc [2021/01/03 16:13] peterlxc:install_lxc [2021/01/07 20:13] (current) peter
Line 8: Line 8:
  
 <code bash> <code bash>
-sudo apt-get install lxc+sudo apt install lxc 
 </code> </code>
  
Line 16: Line 16:
  
 ---- ----
 +
 +===== Install LXC Utils =====
 +
 +<code bash>
 +sudo apt install lxc-utils lxc-templates
 +</code>
 +
 +----
 +
  
 ===== Get Info ===== ===== Get Info =====
Line 60: Line 69:
  
 </WRAP> </WRAP>
 +
 +----
 +
 +===== Create ~/.config/lxc =====
 +
 +<code bash>
 +mkdir ~/.config/lxc
 +</code>
 +
 +----
 +
 +===== Create ~/.config/lxc/default.conf =====
 +
 +<file bash ~/.config/lxc/default.conf>
 +lxc.include = /etc/lxc/default.conf
 +lxc.idmap = u 0 100000 65536
 +lxc.idmap = g 0 100000 65536
 +</file>
 +
 +----
 +
 +===== Test =====
 +
 +<code bash>
 +lxc-create -t download -n test
 +</code>
 +
 +<WRAP info>
 +**NOTE:**  The **download** option is used to display a list of all available images, allowing one to be selected.
 +</WRAP>
 +
 +
 +<WRAP info>
 +**NOTE:**  An error may be seen:
 +
 +<code bash>
 +Setting up the GPG keyring
 +ERROR: Unable to fetch GPG key from keyserver
 +lxc-create: test: lxccontainer.c: create_run_template: 1626 Failed to create container from template
 +lxc-create: test: tools/lxc_create.c: main: 319 Failed to create container test
 +</code>
 +
 +Try using the following:
 +
 +<code bash>
 +lxc-create -t download -n test -- --keyserver hkp://p80.pool.sks-keyservers.net:80
 +</code>
 +
 +or
 +
 +<code bash>
 +lxc-create -n test -t download -- --no-validate
 +</code>
 +
 +</WRAP>
 +
 +returns:
 +
 +<code bash>
 +Setting up the GPG keyring
 +Downloading the image index
 +
 +---
 +DIST RELEASE ARCH VARIANT BUILD
 +---
 +alpine 3.10 amd64 default 20210103_13:00
 +alpine 3.10 arm64 default 20210103_13:00
 +alpine 3.10 armhf default 20210103_13:00
 +alpine 3.10 i386 default 20210103_13:00
 +...
 +centos 8 amd64 default 20210103_07:41
 +centos 8 arm64 default 20210103_07:08
 +centos 8 ppc64el default 20210103_07:08
 +debian bullseye amd64 default 20210103_05:24
 +debian bullseye arm64 default 20210103_05:24
 +...
 +ubuntu trusty arm64 default 20210103_07:42
 +ubuntu trusty armhf default 20210103_07:42
 +ubuntu trusty i386 default 20210103_07:42
 +ubuntu trusty ppc64el default 20210103_07:42
 +ubuntu xenial amd64 default 20210103_07:42
 +ubuntu xenial arm64 default 20210103_07:43
 +ubuntu xenial armhf default 20210103_07:43
 +...
 +</code>
 +
 +----
 +
 +==== Select which image to use ====
 +
 +In this example the following is chosen:
 +
 +  * Distribution:  **ubuntu**.
 +  * Release:  **xenial**.
 +  * Architecture:  **amd64**.
 +
 +
 +<code bash>
 +Distribution: 
 +ubuntu
 +Release: 
 +xenial
 +Architecture: 
 +amd64
 +
 +Downloading the image index
 +Downloading the rootfs
 +Downloading the metadata
 +The image cache is now ready
 +Unpacking the rootfs
 +
 +---
 +
 +You just created an Ubuntu xenial amd64 (20210103_07:42) container.
 +
 +To enable SSH, run: apt install openssh-server
 +No default root or user password are set by LXC.
 +</code>
 +
 +
 +----
 +
 +==== Check the container status ====
 +
 +<code bash>
 +lxc-info -n test
 +</code>
 +
 +returns:
 +
 +<code bash>
 +Name:           test
 +State:          STOPPED
 +</code>
 +
 +----
 +
 +==== Start the Container ====
 +
 +<code bash>
 +lxc-start -n test
 +</code>
 +
 +<WRAP info>
 +**NOTE:**  The following error may be seen:
 +
 +<code bash>
 +lxc-start: test: lxccontainer.c: wait_on_daemonized_start: 851 Received container state "ABORTING" instead of "RUNNING"
 +lxc-start: test: tools/lxc_start.c: main: 308 The container failed to start
 +lxc-start: test: tools/lxc_start.c: main: 311 To get more details, run the container in foreground mode
 +lxc-start: test: tools/lxc_start.c: main: 313 Additional information can be obtained by setting the --logfile and --logpriority options
 +</code>
 +
 +By default, unprivileged users are not allowed to create any network device on the host.  To fix:
 +
 +<file bash /etc/lxc/lxc-usernet>
 +peter veth lxcbr0 10
 +</file>
 +
 +<WRAP info>
 +**NOTE:**  This means that peter is allowed to create up to 10 veth devices connected to the lxcbr0 bridge.
 +</WRAP>
 +
 +
 +</WRAP>
 +
 +----
 +
 +==== Check the container status again ====
 +
 +<code bash>
 +lxc-info -n test
 +</code>
 +
 +returns:
 +
 +<code bash>
 +Name:           test
 +State:          RUNNING
 +PID:            793414
 +IP:             10.0.3.101
 +Link:           veth1000_qkOr
 + TX bytes:      1.96 KiB
 + RX bytes:      11.54 KiB
 + Total bytes:   13.49 KiB
 +</code>
 +
 +<WRAP info>
 +**NOTE:**  This shows it is running.
 +</WRAP>
 +
 +----
 +
 +==== Get a Shell inside the Container ====
 +
 +<code bash>
 +lxc-attach -n test
 +</code>
 +
 +<WRAP info>
 +**NOTE:**  Enter **exit** to exit the Container Shell, back to the host.
 +</WRAP>
 +
 +
 +----
 +
 +==== Stop the Test Container ====
 +
 +<code bash>
 +lxc-stop -n test
 +</code>
 +
 +----
 +
 +==== Remove the Test Container ====
 +
 +<code bash>
 +lxc-destroy -n test
 +</code>
  
 ---- ----
lxc/install_lxc.1609690430.txt.gz · Last modified: 2021/01/03 16:13 by peter

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki