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:

#!/bin/bash
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;;
esac

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
sh-4.2#

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:

(No Ratings Yet)
Loading...
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.

Follow me on Twitter

Archives

vceplus-200-125    | boson-200-125    | training-cissp    | actualtests-cissp    | techexams-cissp    | gratisexams-300-075    | pearsonitcertification-210-260    | examsboost-210-260    | examsforall-210-260    | dumps4free-210-260    | reddit-210-260    | cisexams-352-001    | itexamfox-352-001    | passguaranteed-352-001    | passeasily-352-001    | freeccnastudyguide-200-120    | gocertify-200-120    | passcerty-200-120    | certifyguide-70-980    | dumpscollection-70-980    | examcollection-70-534    | cbtnuggets-210-065    | examfiles-400-051    | passitdump-400-051    | pearsonitcertification-70-462    | anderseide-70-347    | thomas-70-533    | research-1V0-605    | topix-102-400    | certdepot-EX200    | pearsonit-640-916    | itproguru-70-533    | reddit-100-105    | channel9-70-346    | anderseide-70-346    | theiia-IIA-CIA-PART3    | certificationHP-hp0-s41    | pearsonitcertification-640-916    | anderMicrosoft-70-534    | cathMicrosoft-70-462    | examcollection-cca-500    | techexams-gcih    | mslearn-70-346    | measureup-70-486    | pass4sure-hp0-s41    | iiba-640-916    | itsecurity-sscp    | cbtnuggets-300-320    | blogged-70-486    | pass4sure-IIA-CIA-PART1    | cbtnuggets-100-101    | developerhandbook-70-486    | lpicisco-101    | mylearn-1V0-605    | tomsitpro-cism    | gnosis-101    | channel9Mic-70-534    | ipass-IIA-CIA-PART1    | forcerts-70-417    | tests-sy0-401    | ipasstheciaexam-IIA-CIA-PART3    | mostcisco-300-135    | buildazure-70-533    | cloudera-cca-500    | pdf4cert-2v0-621    | f5cisco-101    | gocertify-1z0-062    | quora-640-916    | micrcosoft-70-480    | brain2pass-70-417    | examcompass-sy0-401    | global-EX200    | iassc-ICGB    | vceplus-300-115    | quizlet-810-403    | cbtnuggets-70-697    | educationOracle-1Z0-434    | channel9-70-534    | officialcerts-400-051    | examsboost-IIA-CIA-PART1    | networktut-300-135    | teststarter-300-206    | pluralsight-70-486    | coding-70-486    | freeccna-100-101    | digitaltut-300-101    | iiba-CBAP    | virtuallymikebrown-640-916    | isaca-cism    | whizlabs-pmp    | techexams-70-980    | ciscopress-300-115    | techtarget-cism    | pearsonitcertification-300-070    | testking-2v0-621    | isacaNew-cism    | simplilearn-pmi-rmp    | simplilearn-pmp    | educationOracle-1z0-809    | education-1z0-809    | teachertube-1Z0-434    | villanovau-CBAP    | quora-300-206    | certifyguide-300-208    | cbtnuggets-100-105    | flydumps-70-417    | gratisexams-1V0-605    | ituonline-1z0-062    | techexams-cas-002    | simplilearn-70-534    | pluralsight-70-697    | theiia-IIA-CIA-PART1    | itexamtips-400-051    | pearsonitcertification-EX200    | pluralsight-70-480    | learn-hp0-s42    | giac-gpen    | mindhub-102-400    | coursesmsu-CBAP    | examsforall-2v0-621    | developerhandbook-70-487    | root-EX200    | coderanch-1z0-809    | getfreedumps-1z0-062    | comptia-cas-002    | quora-1z0-809    | boson-300-135    | killtest-2v0-621    | learncia-IIA-CIA-PART3    | computer-gcih    | universitycloudera-cca-500    | itexamrun-70-410    | certificationHPv2-hp0-s41    | certskills-100-105    | skipitnow-70-417    | gocertify-sy0-401    | prep4sure-70-417    | simplilearn-cisa    |
http://www.pmsas.pr.gov.br/wp-content/    | http://www.pmsas.pr.gov.br/wp-content/    |