RHEL7: How to get started with Linux containers.

Share this link

Installation Procedure

At first, you need to install the libvirt-sandbox package:

# yum install -y libvirt-sandbox

Note: Before RHEL 7 was released (RHEL 7 Beta, RHEL 7 RC, etc), there was a libvirt-sandbox package available in the main repository.
It’s not the case anymore and you need to build it manually through http://sandbox.libvirt.org/.

Then, you need to start the libvirtd daemon:

# systemctl start libvirtd

And to enable it at boot:

# systemctl enable libvirtd

Now, create the following bash script called cont:

case $1 in
create) virt-sandbox-service -c lxc:/// create --copy --unit $3 $2 ;;
delete) virt-sandbox-service -c lxc:/// delete $2 ;;
start) systemctl start $2_sandbox ;;
stop) systemctl stop $2_sandbox ;;
list) virsh -c lxc:/// list --all ;;
connect) virt-sandbox-service connect $2;;
enable) virsh -c lxc:/// autostart $2;;
disable) virsh -c lxc:/// autostart --disable $2;;
dominfo) virsh -c lxc:/// dominfo $2;;

And, make it executable:

# chmod u+x cont

Now, it’s time to test.
Let’s say, we want a httpd server container called apache:

# ./cont create apache httpd
Created sandbox container dir /var/lib/libvirt/filesystems/apache
Created unit file /etc/systemd/system/apache_sandbox.service
Created sandbox config /etc/libvirt-sandbox/services/apache/config/sandbox.cfg

We want to start it:

# ./cont start apache

Is it really started?

# ./cont list
Id Name State
6818 apache running

Is it possible to get more details?

# ./cont dominfo apache
Id: 6818
Name: apache
UUID: cc897ced-4b82-4a38-ad4d-55b28023e093
OS Type: exe
State: running
CPU(s): 1
CPU time: 0.6s
Max memory: 524288 KiB
Used memory: 6808 KiB
Persistent: yes
Autostart: disable
Managed save: unknown
Security model: selinux
Security DOI: 0
Security label: system_u:system_r:svirt_lxc_net_t:s0 (enforcing)

We want it to start at boot:

# ./cont enable apache
Domain apache marked as autostarted

We want to connect to it:

# ./cont connect apache

Now, we want to leave it:

sh-4.2# exit

If we don’t need it anymore, we can stop it and destroy it:

# ./cont stop apache
# ./cont delete apache

Note1: As it was marked as autostarted, if we didn’t destroy it, it would have been restarted at the next reboot of the host.
Note2: The cont script is only there to avoid typing more complicated commands.

Additional Resources

In addition, you can look at Dan Walsh’s presentation at DevConf.cz 2014 or watch his videos:

1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)
11 comments on “RHEL7: How to get started with Linux containers.
  1. inverter says:

    What repo are you using for the libvirt-sandbox rpm? I’m trying to install but says it doesn’t exist in repo or on the RedHat 7 cd. Any information would be appreciated.

  2. symgryph says:

    I got things compiling, (RHEL 7.3) and installed but get the following when trying to follow the tutorial:

    Traceback (most recent call last):
    File “/bin/virt-sandbox-service”, line 25, in
    gi.require_version(‘LibvirtSandbox’, ‘1.0’)
    File “/usr/lib64/python2.7/site-packages/gi/__init__.py”, line 81, in require_version
    raise ValueError(‘Namespace %s not available’ % namespace)
    ValueError: Namespace LibvirtSandbox not available
    [root@Builder 3.10.0-514.2.2.el7.x86_64]#

    I did enable ‘namespaces’ in the boot options, but no idea how to fix it.

Leave a Reply

Upcoming Events (Local Time)

There are no events.

RHCSA7: Task of the day

Allowed time: 10 minutes.
Archive and compress the content of the /opt directory (create files if none exists).
Uncompress and unarchive the resulting file in /root

RHCE7: Task of the day

Allowed time: 15 minutes.
Configure a Samba server called MYSERVER, belonging to the MYGROUP group, sharing the /shared directory with the name "shared".

Follow me on Twitter

Poll for favorite RHEL 7 book

What is your favorite RHEL 7 book to prepare RHCSA & RHCE exams?

View Results

Loading ... Loading ...

Poll for most difficult RHCSA 7 topic

What do you think is the most difficult RHCSA 7 topic?

View Results

Loading ... Loading ...

Poll for most difficult RHCE 7 topic

What do you think is the most difficult RHCE 7 topic?

View Results

Loading ... Loading ...