Shell helpers to setup LXC hypervisors
Go to file
earl-warren 231215c11d
All checks were successful
/ test (push) Successful in 13m2s
Merge pull request 'Use latest Helm chart version in LXC test' (#22) from Xinayder/forgejo-lxc-helpers:k3s into main
Reviewed-on: #22
Reviewed-by: earl-warren <>
2023-12-09 22:48:30 +00:00
.forgejo lxc_config test needs lxc 2023-12-04 20:34:16 +01:00
.gitignore initial implementation 2023-05-16 23:14:54 +02:00
LICENSE initial implementation 2023-05-16 23:14:54 +02:00 Add debug flag and increase install timeout 2023-12-09 15:31:41 +00:00 launch docker with IPv6 always 2023-12-02 16:40:55 +01:00 add IPv6 support 2023-12-01 22:19:22 +01:00 document the lxc_install_docker command 2023-12-01 21:40:13 +01:00 keep the existing test to ensure backward compatibility 2023-09-16 19:18:29 +02:00

LXC helpers

A set of LXC shell functions to help with:


$ git clone
$ cd lxc-helpers
$ ./ lxc_container_create mycontainer
$ ./ lxc_container_start mycontainer
$ ./ lxc_container_run mycontainer date
Mon May 29 10:46:57 CEST 2023
$ ./ lxc_container_stop mycontainer
$ ./ lxc_container_destroy mycontainer


$ --help - LXC container management helpers

SYNOPSIS [-v|--verbose] [-h|--help]
		  [-o|--os {bookworm|bullseye} (default bookworm)]
		  command [arguments] [-v|--verbose] [-h|--help]
		  [-o|--os {bookworm|bullseye} (default bookworm)]
		  [-c|--config {unprivileged lxc libvirt docker k8s} (default "lxc libvirt docker")]
		  lxc_container_create [arguments]


   A thin shell based layer on top of LXC to create, populate, run and
   destroy LXC containers. A container is created from a copy of an
   existing container.



       Install LXC dependencies.

   lxc_container_create `name`

       Create the `name` container.

   lxc_container_mount `name` `path`

       Configure `name` container to bind mount `path` so that it is
       also accessible at `path` from within the container.

   lxc_container_start `name`

       Start the `name` container.

   lxc_container_stop `name`

       Stop the `name` container.

   lxc_container_destroy `name`

       Call lxc_container_stop `name` and destroy the container.


       Echo the name of the container for the Operating System
       specified with `--os`.

   lxc_build_template `existing_container` `new_container`

       Copy `existing_container` into `new_container`. If
       `existing_container` is equal to $( lxc_template_release) it
       will be created on demand.


   The `--config` option provides preset configurations appended to the `/var/lib/lxc/name/config`
   file when the container is created with the `lxc_container_create` command. They are required
   to run the corresponding subsystem:

     * `docker`
     * `lxc`
     * `libvirt`
     * `k8s`
     * `unprivileged` none of the above

   Example: --config "docker libvirt" lxc_container_create mycontainer

   The `unprivileged` configuration does not add anything.


   For some command lxc_something `name` that can be called from outside the container
   there is an equivalent function lxc_something_inside that can be called from inside
   the container.

   lxc_install_lxc `name` `prefix`
   lxc_install_lxc_inside `prefix`

      Install LXC in the `name` container to allow the creation of
      nested containers. `prefix` is a class C IP prefix from which
      containers will obtain their IP (for instance 10.40.50).

   lxc_install_docker `name`

      Install Docker in the `name` container.

   lxc_container_run `name` command [options...]

      Run the `command` within the `name` container.

   lxc_container_run_script `name` `path`
   lxc_container_run_script_as `name` `user` `path`

      Run the script found at `path` within the `name` container. The
      environment is cleared before running the script. The first form
      will run as root, the second form will impersonate `user`.

   lxc_container_user_install `name` `user_id` `user` [`homedir` default `/home`]

      Create the `user` with `user_id` in the `name` container with a
      HOME at `/homedir/user`. Passwordless sudo permissions are
      granted to `user`. It is made a member of the groups docker, kvm
      and libvirt if they exist already. A SSH key is created.

      Example: lxc_container_user_install mycontainer $(id -u) $USER