Instantiating Containers from Base Images with LXC/LXD

30 minutes
  • 3 Learning Objectives

About this Hands-on Lab

With containers being an important part of any dynamic IT organization, understanding how to work with them is a key component to your success as an engineer. In this activity, you will get a chance with work with images and instantiuate containers using the LXD/LXC container management engine. Once you complete this activity, you will have an understanding of how to pull, start and connect to LXC containers running on your host.

Learning Objectives

Successfully complete this lab by achieving the following learning objectives:

Reconfigure the LXC/LXD Host

Using the requirements from your Activity Guide, you will need to reconfigure the host to be sure the settings are as intended. You can accomplish that with the following command:

sudo lxd init
Non-privileges User ‘cloud_user’ Needs to Be Able to Run LXC Commands

Check /etc/groups, look for the ‘lxd’ group. If the ‘cloud_user’ user is not a member, then do:

sudo usermod -aG lxd cloud_user

To add them. You WILL Have to log completely off and back in for the membership to pick up in the shell (or start a new bash instance without logging out)

Pull a CentOS 7 Image and Run a Container

You can launch a container instance called ‘myweb’ based on the CentOS 7 image provided by the default repositories with the command:

lxc launch images:centos/7 myweb

You can verify with

lxc list

Which will show the running container. Connecting to it can be done via:

lxc exec myweb -- /bin/bash

You will be logged into the container. You can log out with ‘exit’ and then stop the container with

lxc stop myweb

Verify the image is still there with

lxc image list

Additional Resources

Upon launching this activity, you will be presented with a single Ubuntu 16.04 LTS server instance. Using the provided credentials and connectivity information, once you are connected, please open the Activity Guide for instructions on completing this Learning Activity.

What are Hands-on Labs

Hands-on Labs are real environments created by industry experts to help you learn. These environments help you gain knowledge and experience, practice without compromising your system, test without risk, destroy without fear, and let you learn from your mistakes. Hands-on Labs: practice your skills before delivering in the real world.

Sign In
Welcome Back!

Psst…this one if you’ve been moved to ACG!

Get Started
Who’s going to be learning?