Howto-lxc-simple: Difference between revisions
mNo edit summary |
m (→Installation (base): use pkg template) |
||
(3 intermediate revisions by 2 users not shown) | |||
Line 1: | Line 1: | ||
[ | [https://linuxcontainers.org/ Linux Containers (LXC)] provides containers similar BSD Jails, Linux VServer and Solaris Zones. It gives the impression of virtualization, but shares the kernel and resources with the "host". | ||
'''NOTE:''' Simple (howto) is meant for using LXC for quick installation of applications using HOSTs networking/ip (container config has, <code>lxc.network.type = none</code> ) and usage of application for development work. Most application have internal settings for PORTs which will be used where multiple versions of that application is needed to install.<br>For production or live environment using [[bridge]] (br0) with [[LXC | full networking]] for container would be ideal, alternate use docker (both requires some experience with container technologies). | '''NOTE:''' Simple (howto) is meant for using LXC for quick installation of applications using HOSTs networking/ip (container config has, <code>lxc.network.type = none</code> ) and usage of application for development work. Most application have internal settings for PORTs which will be used where multiple versions of that application is needed to install.<br>For production or live environment using [[bridge]] (br0) with [[LXC | full networking]] for container would be ideal, alternate use docker (both requires some experience with container technologies). | ||
Line 9: | Line 9: | ||
== Installation (base) == | == Installation (base) == | ||
Install the required packages: | Install the required packages: | ||
{{Cmd|apk add lxc lxc-templates bridge}} | {{Cmd|apk add {{pkg|lxc|arch=}} {{pkg|lxc-templates|arch=}} {{pkg|bridge|arch=}}}} | ||
Create a simple configuration template for the guests, ''/etc/lxc/simple.conf'': | Create a simple configuration template for the guests, ''/etc/lxc/simple.conf'': | ||
Line 34: | Line 34: | ||
You can start your guest with: | You can start your guest with: | ||
{{Cmd| | {{Cmd|rc-service lxc.dev1 start}} | ||
Stop it with: | Stop it with: | ||
{{Cmd| | {{Cmd|rc-service lxc.dev1 stop}} | ||
Make it autostart on boot up with: | Make it autostart on boot up with: | ||
Line 65: | Line 65: | ||
== Advanced == | == Advanced == | ||
see [[bridge | setting bridge (device: br0)]] with [[LXC | LXC full networking]] | see [[bridge | setting bridge (device: br0)]] with [[LXC | LXC full networking]] | ||
[[Category:Security]] | |||
[[Category:Virtualization]] |
Latest revision as of 09:17, 19 January 2024
Linux Containers (LXC) provides containers similar BSD Jails, Linux VServer and Solaris Zones. It gives the impression of virtualization, but shares the kernel and resources with the "host".
NOTE: Simple (howto) is meant for using LXC for quick installation of applications using HOSTs networking/ip (container config has, lxc.network.type = none
) and usage of application for development work. Most application have internal settings for PORTs which will be used where multiple versions of that application is needed to install.
For production or live environment using bridge (br0) with full networking for container would be ideal, alternate use docker (both requires some experience with container technologies).
Target audience: Developers, Newbies
Tested on: AlpineLinux v3.3x(host+guest)
Installation (base)
Install the required packages:
apk add lxc lxc-templates bridge
Create a simple configuration template for the guests, /etc/lxc/simple.conf:
lxc.network.type = none
Create a guest
Using Alpine Template
lxc-create -n dev1 -f /etc/lxc/simple.conf -t alpine
This will create a /var/lib/lxc/dev1 directory with a config file and a rootfs directory.
If running on x86_64 architecture, it is possible to create a 32bit guest:
lxc-create -n dev1 -f /etc/lxc/simple.conf -t alpine -- --arch x86
Starting/Stopping the guest
Create a symlink to the /etc/init.d/lxc script for your guest.
ln -s lxc /etc/init.d/lxc.dev1
You can start your guest with:
rc-service lxc.dev1 start
Stop it with:
rc-service lxc.dev1 stop
Make it autostart on boot up with:
rc-update add lxc.dev1
You can also add to the container config: lxc.start.auto = 1
&
rc-update add lxc
to autostart containers by the lxc service only.
Connecting to the guest
By default sshd is not installed, so you will have to connect to a virtual console. This is done with:
lxc-console -n dev1
To disconnect from it, press Ctrl+a q
Deleting a guest
Make sure the guest is stopped before removal:
lxc-stop -n dev1
lxc-destroy -n dev1
This will erase everything, without asking any questions. It is equivalent to:
rm -r /var/lib/lxc/dev1