Enjoy Slackware 15.0!
Differences
This shows you the differences between two versions of the page.
Next revision | Previous revision Next revision Both sides next revision | ||
howtos:misc:lxc [2018/09/14 04:27 (UTC)] montagdude created |
howtos:misc:lxc [2018/09/15 20:56 (UTC)] montagdude [Sharing Directories with the Host] Slight wording change |
||
---|---|---|---|
Line 4: | Line 4: | ||
===== Introduction ===== | ===== Introduction ===== | ||
- | Linux Containers, or LXC, is operating system-level method for running multiple separate isolated Linux installations (containers) on a single host. Rather than simulating the computer hardware as in true virtualization, | + | Linux Containers, or LXC, is operating system-level method for running multiple separate isolated Linux installations (containers) on a single host. Rather than simulating the computer hardware as in true virtualization, |
===== Setting up a Network Bridge ===== | ===== Setting up a Network Bridge ===== | ||
Line 22: | Line 22: | ||
</ | </ | ||
- | If it worked, there should not be any error messages or other output. You can check that it worked with ifconfig: | + | Note that you may need to create the directory / |
< | < | ||
Line 36: | Line 36: | ||
</ | </ | ||
- | The name of the bridge, gateway, netmask, and many other parameters can be modified in / | + | The name of the bridge, gateway, netmask, and many other parameters can be modified |
To actually use this network within the container, there are a few steps that will need to be taken during the initial creation and setup of the container, which will be covered in the next section. | To actually use this network within the container, there are a few steps that will need to be taken during the initial creation and setup of the container, which will be covered in the next section. | ||
+ | |||
+ | ===== Creating a Container ===== | ||
+ | |||
+ | To create a new container, the lxc-create command will be used. However, there are some initial configuration steps you may want to take first. By default, all containers will go in / | ||
+ | |||
+ | < | ||
+ | lxc.lxcpath = / | ||
+ | </ | ||
+ | |||
+ | The basic command to create a new container is as follows: | ||
+ | |||
+ | < | ||
+ | lxc-create -n container_name -t template_name -f / | ||
+ | </ | ||
+ | |||
+ | The config file, specified after the -f flag, can be fairly simple. Here is a sample, which sets only some network parameters: | ||
+ | |||
+ | < | ||
+ | lxc.network.type = veth | ||
+ | lxc.network.flags = up | ||
+ | lxc.network.link = lxcbr0 | ||
+ | </ | ||
+ | |||
+ | This sample config uses a virtual ethernet interface connecting to the bridge on the host called lxcbr0. For additional available configuration options, see the lxc.container.conf manpage. Note that once the container is created, a new config file will be created within the container' | ||
+ | |||
+ | The template file, specified after the -t flag, can be any of the ones present in / | ||
+ | |||
+ | < | ||
+ | lxc-create -n container_name -t slackware -f / | ||
+ | </ | ||
+ | |||
+ | The Slackware template accepts a number of environment variables. The most important of these are release and arch. release defaults to current, and arch defaults to the architecture of the host machine. It is also possible to specify the slackpkg mirror as an environment variable. For example, here is how one could create a container for Slackware64-14.2 using a US mirror: | ||
+ | |||
+ | < | ||
+ | arch=x86_64 release=14.2 MIRROR=http:// | ||
+ | </ | ||
+ | |||
+ | When lxc-create is executed, the container will be created at $lxcpath/ | ||
+ | |||
+ | ===== Container Configuration ===== | ||
+ | |||
+ | After creating the container, you are almost ready to go. First start the container: | ||
+ | |||
+ | < | ||
+ | lxc-start -n container_name | ||
+ | </ | ||
+ | |||
+ | To log in, use: | ||
+ | |||
+ | < | ||
+ | lxc-console -n container_name | ||
+ | </ | ||
+ | |||
+ | or | ||
+ | |||
+ | < | ||
+ | lxc-attach -n container_name | ||
+ | </ | ||
+ | |||
+ | The first variant will give you a login console on the container, whereas the second will just give you a root shell without asking for a password. The first thing to do is to create a new user; use the standard Slackware tools such as // | ||
+ | |||
+ | ==== Network ==== | ||
+ | |||
+ | Even if you successfully set up a bridge network on the host and configured your container to use a virtual ethernet interface as described above, at this point you will probably still not have network access in the container. The reason is that you still need to set up your container' | ||
+ | |||
+ | < | ||
+ | USE_DHCP[0]=" | ||
+ | </ | ||
+ | |||
+ | If desired, it should be possible to use a static IP address in the container as well. | ||
+ | |||
+ | <note tip> | ||
+ | The minimal Slackware installation set up by lxc-create does not have a lot of choice in editors, but //vi// (symlink to //elvis//) is available. If that's not your cup of tea, you can always edit the container' | ||
+ | </ | ||
+ | |||
+ | Once you have edited / | ||
+ | |||
+ | < | ||
+ | lxc-stop -n container_name | ||
+ | lxc-start -n container_name | ||
+ | </ | ||
+ | |||
+ | Wait a minute or so to give the container plenty of time to " | ||
+ | |||
+ | < | ||
+ | # lxc-ls --fancy | ||
+ | NAME STATE | ||
+ | Slackware-14.2 | ||
+ | Slackware64-14.2 | ||
+ | Slackware64-current STOPPED 0 | ||
+ | </ | ||
+ | |||
+ | If the container successfully connected to the network, you should see that an IP address has been assigned. Log into the container again, and you should be able to ping outside, use slackpkg, etc. At this point, you can install any additional software you desire on the container. If you are using the container as a build environment, | ||
+ | |||
+ | < | ||
+ | slackpkg install slackware | ||
+ | </ | ||
+ | |||
+ | or | ||
+ | |||
+ | < | ||
+ | slackpkg install slackware64 | ||
+ | </ | ||
+ | |||
+ | ==== Sharing Directories with the Host ==== | ||
+ | |||
+ | Because an LXC container' | ||
+ | |||
+ | < | ||
+ | lxc.mount.entry = / | ||
+ | </ | ||
+ | |||
+ | Note that the second path intentionally lacks a leading slash. This is because it is a relative path -- relative to the container' | ||
+ | |||
+ | ====== See Also ====== | ||
+ | |||
+ | [[https:// | ||
+ | |||
+ | [[https:// | ||
+ | |||
+ | [[https:// | ||
+ | |||
+ | [[https:// | ||
====== Sources ====== | ====== Sources ====== | ||
Line 44: | Line 167: | ||
<!-- * Original source: [[http:// | <!-- * Original source: [[http:// | ||
<!-- Authors are allowed to give credit to themselves! --> | <!-- Authors are allowed to give credit to themselves! --> | ||
- | < | + | * Originally written by [[wiki: |
<!-- * Contributions by [[wiki: | <!-- * Contributions by [[wiki: | ||