Howto-lxc-simple: Difference between revisions

From Alpine Linux
(How to setup LXC (simple) on Alpine Linux)
 
mNo edit summary
Line 5: Line 5:
'''Target audience:''' Developers, Newbies
'''Target audience:''' Developers, Newbies


'''Tested on:''' AlpineLinux v3.3x
'''Tested on:''' AlpineLinux v3.3x(host+guest)


== Installation (base) ==
== Installation (base) ==

Revision as of 22:39, 18 February 2016

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:

/etc/init.d/lxc.dev1 start

Stop it with:

/etc/init.d/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

Installing applications in simple LXC containers

1. Installing LAMP (simple)

Advanced

see setting bridge (device: br0) with LXC full networking