LXD/LXC Basic Setup: Difference between revisions
From WikiMLT
mNo edit summary |
m (→References) |
||
Line 1: | Line 1: | ||
<noinclude>{{ContentArticleHeader/Linux_Server|toc=off}}{{ContentArticleHeader/Containers}}</noinclude> | <noinclude>{{ContentArticleHeader/Linux_Server|toc=off}}{{ContentArticleHeader/Containers}}</noinclude> | ||
== LXD Initial Setup == | |||
<syntaxhighlight lang="shell" line="1"> | |||
sudo usermod -aG lxd <user> | |||
</syntaxhighlight> | |||
Initialize LXD. | |||
{{collapse/begin}} | |||
<syntaxhighlight lang="shell" line="1"> | |||
lxd init | |||
</syntaxhighlight> | |||
{{collapse/div|#Output}} | |||
<syntaxhighlight lang="shell-session" class="mlw-continue mlw-collapsed-first-element mlw-pre-max-height-320"> | |||
Would you like to use LXD clustering? (yes/no) [default=no]: no | |||
Do you want to configure a new storage pool? (yes/no) [default=yes]: yes | |||
Name of the new storage pool [default=default]: default | |||
Name of the storage backend to use (dir, lvm, zfs, ceph, btrfs) [default=zfs]: dir | |||
Would you like to connect to a MAAS server? (yes/no) [default=no]: no | |||
Would you like to create a new local network bridge? (yes/no) [default=yes]: yes | |||
What should the new bridge be called? [default=lxdbr0]: lxdbr0 | |||
What IPv4 address should be used? (CIDR subnet notation, “auto” or “none”) [default=auto]: auto | |||
What IPv6 address should be used? (CIDR subnet notation, “auto” or “none”) [default=auto]: auto | |||
Would you like the LXD server to be available over the network? (yes/no) [default=no]: no | |||
Would you like stale cached images to be updated automatically? (yes/no) [default=yes]: yes | |||
Would you like a YAML "lxd init" preseed to be printed? (yes/no) [default=no]: yes | |||
</syntaxhighlight> | |||
<syntaxhighlight lang="shell-session" class="mlw-continue mlw-pre-max-height-320"> | |||
config: {} | |||
networks: | |||
- config: | |||
ipv4.address: auto | |||
ipv6.address: auto | |||
description: "" | |||
name: lxdbr0 | |||
type: "" | |||
project: default | |||
storage_pools: | |||
- config: {} | |||
description: "" | |||
name: default | |||
driver: dir | |||
profiles: | |||
- config: {} | |||
description: "" | |||
devices: | |||
eth0: | |||
name: eth0 | |||
network: lxdbr0 | |||
type: nic | |||
root: | |||
path: / | |||
pool: default | |||
type: disk | |||
name: default | |||
projects: [] | |||
cluster: null | |||
</syntaxhighlight> | |||
{{collapse/end}} | |||
List the available images by the command: <code>lxc image list ubuntu:22.04 | grep x86_64</code>. Then install a certain image and name the container <code>'''lxc-webserver'''</code>, that will be capable to run other containers inside, for more details read the article [https://ubuntu.com/blog/nested-containers-in-lxd Nested containers in LXD]. | |||
{{collapse/begin}} | |||
<syntaxhighlight lang="shell" line="1"> | |||
lxc launch ubuntu:22.04 lxc-webserver -c security.nesting=true | |||
</syntaxhighlight> | |||
{{collapse/div|#Output}} | |||
<syntaxhighlight lang="shell-session" class="mlw-collapsed-first-element"> | |||
Creating lxc-webserver | |||
Starting lxc-webserver | |||
</syntaxhighlight> | |||
<p>In order to add (or remove) the nesting option to an existing LXC, use:</p> | |||
<syntaxhighlight lang="shell" class=""> | |||
lxc config set lxc-webserver security.nesting true | |||
</syntaxhighlight> | |||
{{collapse/end}} | |||
{{collapse/begin}} | |||
<syntaxhighlight lang="shell" line="1"> | |||
lxc list --columns ns4 # name, state and IPv4 | |||
</syntaxhighlight> | |||
{{collapse/div|#Output}} | |||
<syntaxhighlight lang="shell-session" class="mlw-continue mlw-collapsed-first-element mlw-pre-max-height-320"> | |||
+---------------+---------+-----------------------+ | |||
| NAME | STATE | IPV4 | | |||
+---------------+---------+-----------------------+ | |||
| lxc-webserver | RUNNING | 10.127.198.222 (eth0) | | |||
+---------------+---------+-----------------------+ | |||
</syntaxhighlight> | |||
{{collapse/end}} | |||
Configure the container to obtain a static IP assignment. <syntaxhighlight lang="shell" line="1"> | |||
lxc config device override lxc-webserver eth0 | |||
</syntaxhighlight> | |||
<syntaxhighlight lang="shell-session" class="mlw-continue mlw-pre-max-height-320"> | |||
Device eth0 overridden for lxc-webserver | |||
</syntaxhighlight> | |||
<syntaxhighlight lang="shell" line="1"> | |||
lxc config device set lxc-webserver eth0 ipv4.address 10.127.198.222 # no output mean everything is fine | |||
lxc restart lxc-webserver | |||
lxc list --columns ns4 | grep eth0 # check the ip | |||
</syntaxhighlight> | |||
<syntaxhighlight lang="shell-session" class="mlw-continue mlw-pre-max-height-320"> | |||
| lxc-webserver | RUNNING | 10.127.198.222 (eth0) | | |||
</syntaxhighlight> | |||
== References == | == References == |
Revision as of 14:26, 8 September 2022
LXD Initial Setup
sudo usermod -aG lxd <user>
Initialize LXD.
lxd init
#Output
Would you like to use LXD clustering? (yes/no) [default=no]: no
Do you want to configure a new storage pool? (yes/no) [default=yes]: yes
Name of the new storage pool [default=default]: default
Name of the storage backend to use (dir, lvm, zfs, ceph, btrfs) [default=zfs]: dir
Would you like to connect to a MAAS server? (yes/no) [default=no]: no
Would you like to create a new local network bridge? (yes/no) [default=yes]: yes
What should the new bridge be called? [default=lxdbr0]: lxdbr0
What IPv4 address should be used? (CIDR subnet notation, “auto” or “none”) [default=auto]: auto
What IPv6 address should be used? (CIDR subnet notation, “auto” or “none”) [default=auto]: auto
Would you like the LXD server to be available over the network? (yes/no) [default=no]: no
Would you like stale cached images to be updated automatically? (yes/no) [default=yes]: yes
Would you like a YAML "lxd init" preseed to be printed? (yes/no) [default=no]: yes
config: {}
networks:
- config:
ipv4.address: auto
ipv6.address: auto
description: ""
name: lxdbr0
type: ""
project: default
storage_pools:
- config: {}
description: ""
name: default
driver: dir
profiles:
- config: {}
description: ""
devices:
eth0:
name: eth0
network: lxdbr0
type: nic
root:
path: /
pool: default
type: disk
name: default
projects: []
cluster: null
List the available images by the command: lxc image list ubuntu:22.04 | grep x86_64
. Then install a certain image and name the container lxc-webserver
, that will be capable to run other containers inside, for more details read the article Nested containers in LXD.
lxc launch ubuntu:22.04 lxc-webserver -c security.nesting=true
#Output
Creating lxc-webserver
Starting lxc-webserver
In order to add (or remove) the nesting option to an existing LXC, use:
lxc config set lxc-webserver security.nesting true
lxc list --columns ns4 # name, state and IPv4
#Output
+---------------+---------+-----------------------+
| NAME | STATE | IPV4 |
+---------------+---------+-----------------------+
| lxc-webserver | RUNNING | 10.127.198.222 (eth0) |
+---------------+---------+-----------------------+
Configure the container to obtain a static IP assignment.
lxc config device override lxc-webserver eth0
Device eth0 overridden for lxc-webserver
lxc config device set lxc-webserver eth0 ipv4.address 10.127.198.222 # no output mean everything is fine
lxc restart lxc-webserver
lxc list --columns ns4 | grep eth0 # check the ip
| lxc-webserver | RUNNING | 10.127.198.222 (eth0) |
References
- DigitalOcean: How To Install and Configure LXD on Ubuntu 20.04
- Linux containers LXD: Getting Started with LXD
- Canonical Ubuntu Server: LXD
- LearnLinuxTV: Getting started with LXD Containerization (Full Guide!)
- Ask Ubuntu: apt-key deprecation warning when updating system
- Ask Ubuntu: At what point is the ~/.bashrc file created?