Install Alpine on LXC: Difference between revisions
m (dl-cdn) |
(neutralize sudo, vim and nano usages) |
||
Line 11: | Line 11: | ||
=== LXC installation === | === LXC installation === | ||
You have to install "lxc" package on your host system. For example, in Arch Linux you can install it by running: | You have to install "lxc" package on your host system. For example, in Arch Linux you can install it by running: | ||
{{Cmd| | {{Cmd|# pacman -S lxc}} | ||
=== Bridge creation === | === Bridge creation === | ||
Line 23: | Line 23: | ||
Copy sample file "bridge" | Copy sample file "bridge" | ||
{{Cmd| | {{Cmd|# cp /etc/netctl/examples/bridge /etc/netctl/myBridge}} | ||
Modify your bridge configuration file as needed (network interfaces: eno1 and tap0 are, of cource, according to your needs) | Modify your bridge configuration file as needed (network interfaces: eno1 and tap0 are, of cource, according to your needs) | ||
{{ | {{cat|/etc/netctl/myBridge|Description{{=}}"Bridge connection" | ||
Interface{{=}}br0 | |||
Connection{{=}}bridge | |||
Interface=br0 | BindsToInterfaces{{=}}(eno1 tap0) | ||
Connection=bridge | IP{{=}}dhcp | ||
BindsToInterfaces=(eno1 tap0) | }} | ||
IP=dhcp | |||
Stop active connection | Stop active connection | ||
{{Cmd| | {{Cmd|# systemctl stop dhcpcd}} | ||
Start your bridge | Start your bridge | ||
{{Cmd| | {{Cmd|# netctl start myBridge}} | ||
Perhaps you may wish to setup your system to start your bridge automatically at boot time. | Perhaps you may wish to setup your system to start your bridge automatically at boot time. | ||
Line 46: | Line 44: | ||
To install Alpine Linux edge version run: | To install Alpine Linux edge version run: | ||
{{Cmd| | {{Cmd|# lxc-create --name alpine-edge -t alpine -- --release edge}} | ||
You can also configure shared directory which will be accessible from both host and container. In this example we make host's /media/d directory available in container | You can also configure shared directory which will be accessible from both host and container. In this example we make host's /media/d directory available in container | ||
{{Cmd| | {{Cmd|# mkdir /var/lib/lxc/alpine-edge/rootfs/media/d}} | ||
Add the following lines to the container's configuration file: | |||
{{ | {{Cat|/var/lib/lxc/alpine-edge/config|... | ||
lxc.network.type {{=}} veth | |||
lxc.network.flags {{=}} up | |||
lxc.network.link {{=}} br0 | |||
lxc.network.type = veth | lxc.mount.entry{{=}}/media/d media/d none bind 0 0 | ||
lxc.network.flags = up | }} | ||
lxc.network.link = br0 | |||
lxc.mount.entry=/media/d media/d none bind 0 0 | |||
Booting container: | Booting container: | ||
{{cmd| | {{cmd|# lxc-start -n alpine-edge}} | ||
Shutting down container: | Shutting down container: | ||
{{cmd| | {{cmd|# lxc-stop -n alpine-edge}} | ||
Going to Alpine Linux console: | Going to Alpine Linux console: | ||
{{cmd| | {{cmd|# lxc-attach -n alpine-edge}} | ||
== Container setup == | == Container setup == | ||
Modify your apk/repositories configuration file | Modify your apk/repositories configuration file. It is recommended to include "main", "testing" and "community" repositories. | ||
{{Cat|/etc/apk/repositories|http://dl-cdn.alpinelinux.org/alpine/edge/main | |||
It is recommended to include "main", "testing" and "community" repositories. | |||
http://dl-cdn.alpinelinux.org/alpine/edge/main | |||
http://dl-cdn.alpinelinux.org/alpine/edge/testing | http://dl-cdn.alpinelinux.org/alpine/edge/testing | ||
http://dl-cdn.alpinelinux.org/alpine/edge/community | http://dl-cdn.alpinelinux.org/alpine/edge/community | ||
}} | |||
Upgrading your Alpine Linux system: | Upgrading your Alpine Linux system: | ||
{{cmd|apk update && apk upgrade -a}} | {{cmd|# apk update && apk upgrade -a}} | ||
Starting services: | Starting services: | ||
{{Cmd|/etc/init.d/service_name start}} | {{Cmd|# /etc/init.d/service_name start}} | ||
or | or | ||
{{Cmd|rc-service service_name start}} | {{Cmd|# rc-service service_name start}} | ||
Adding services to autostart | Adding services to autostart | ||
{{Cmd|rc-update add service_name}} | {{Cmd|# rc-update add service_name}} | ||
Restarting your container: | Restarting your container: |
Latest revision as of 13:32, 25 August 2023
LXC
LXC is an operating-system-level virtualization method for running multiple isolated Linux systems (containers) on a control host using a single Linux kernel.
With LXC you can run Alpine Linux on container and start services in it using native Alpine Linux' init system (openrc).
This is instruction on how to install Alpine Linux on LXC container.
Preparation
LXC installation
You have to install "lxc" package on your host system. For example, in Arch Linux you can install it by running:
# pacman -S lxc
Bridge creation
You also have to create network bridge on your host.
Setting up bridge in Arch Linux or Arch Linux based systems
Setting up bridge in Ubuntu or Ubuntu based systems
Here is example, how to setup bridge with netctl:
Copy sample file "bridge"
# cp /etc/netctl/examples/bridge /etc/netctl/myBridge
Modify your bridge configuration file as needed (network interfaces: eno1 and tap0 are, of cource, according to your needs)
Contents of /etc/netctl/myBridge
Stop active connection
# systemctl stop dhcpcd
Start your bridge
# netctl start myBridge
Perhaps you may wish to setup your system to start your bridge automatically at boot time.
Container creation
To install Alpine Linux edge version run:
# lxc-create --name alpine-edge -t alpine -- --release edge
You can also configure shared directory which will be accessible from both host and container. In this example we make host's /media/d directory available in container
# mkdir /var/lib/lxc/alpine-edge/rootfs/media/d
Add the following lines to the container's configuration file:
Contents of /var/lib/lxc/alpine-edge/config
Booting container:
# lxc-start -n alpine-edge
Shutting down container:
# lxc-stop -n alpine-edge
Going to Alpine Linux console:
# lxc-attach -n alpine-edge
Container setup
Modify your apk/repositories configuration file. It is recommended to include "main", "testing" and "community" repositories.
Contents of /etc/apk/repositories
Upgrading your Alpine Linux system:
# apk update && apk upgrade -a
Starting services:
# /etc/init.d/service_name start
or
# rc-service service_name start
Adding services to autostart
# rc-update add service_name
Restarting your container:
reboot