Book Image

Containerization with LXC

Book Image

Containerization with LXC

Overview of this book

In recent years, containers have gained wide adoption by businesses running a variety of application loads. This became possible largely due to the advent of kernel namespaces and better resource management with control groups (cgroups). Linux containers (LXC) are a direct implementation of those kernel features that provide operating system level virtualization without the overhead of a hypervisor layer. This book starts by introducing the foundational concepts behind the implementation of LXC, then moves into the practical aspects of installing and configuring LXC containers. Moving on, you will explore container networking, security, and backups. You will also learn how to deploy LXC with technologies like Open Stack and Vagrant. By the end of the book, you will have a solid grasp of how LXC is implemented and how to run production applications in a highly available and scalable way.
Table of Contents (17 chapters)
Containerization with LXC
Credits
About the Author
About the Reviewer
www.PacktPub.com
Customer Feedback
Dedication
Preface

Putting it all together – building a simple RESTful API to LXC with Python


With all the knowledge we have in hand by experimenting with the LXC bindings for Python earlier, we can write a simple RESTful API that will build, manage, and destroy LXC containers.

Note

To keep the code as simple as possible, we are going to skip all error and exception handling and any input validation from the program.

One of the simplest Python web frameworks for building APIs is Bottle. Let's install it first:

root@ubuntu:~# source lxc_python/bin/activate
(lxc_python) root@ubuntu:~# pip install bottle
Collecting bottle
  Downloading bottle-0.12.9.tar.gz (69kB)
    100% |████████████████████████████████| 71kB 7.1MB/s
Building wheels for collected packages: bottle
  Running setup.py bdist_wheel for bottle ... done
  Stored in directory: 
/root/.cache/pip/wheels/6e/87/89/f7ddd6721f4a208d44f2dac02f281b2403a314dd735d2b0e61
Successfully built bottle
Installing collected packages: bottle
Successfully installed...