Managing Files on LXD Containers

15 minutes
  • 3 Learning Objectives

About this Hands-on Lab

LXD offers a command-line interface for efficiently managing files on our Linux containers. We can both push and pull files to and from our containers, or leverage the `edit` command to edit files without ever having to log in to the container directly. In this lab, we’ll be using all of these commands to configure Apache on an Ubuntu Linux host.

Learning Objectives

Successfully complete this lab by achieving the following learning objectives:

Create the containerhub Configuration
  1. Copy an existing profile:

    lxc file pull web01/etc/apache2/sites-available/000-default.conf containerhub.conf
  2. Update the containerhub.conf file:

    vim containerhub.conf
    <VirtualHost *:80>
     ServerName www.containerhub.example
     ServerAdmin hub@localhost
     DocumentRoot /var/www/html
     ErrorLog ${APACHE_LOG_DIR}/error.log
     CustomLog ${APACHE_LOG_DIR}/access.log combined
  3. Push the file to the container:

    lxc file push containerhub.conf web01/etc/apache2/sites-available/containerhub.conf
  4. Confirm the file was added:

    lxc file edit web01/etc/apache2/sites-available/containerhub.conf
Enable the New Configuration
  1. Remove the old 000-default.conf configuration from the sites-enabled directory:

    lxc file delete web01/etc/apache2/sites-enabled/000-default.conf
  2. Enable the new configuration:

    lxc exec web01 -- a2ensite containerhub
    lxc exec web01 -- systemctl reload apache2
Test the New Configuration
  1. Update the index.html file to say a simple sentence:

    lxc file edit web01/var/www/html/index.html
    Website test
  2. Retrieve the private IP address of the container:

    lxc list
  3. Curl the website:

    curl <web01_private_ip>

Additional Resources

As part of your team's goal of lifting-and-shifting some legacy applications off of virtual machines and on to containers, you need a working web server container image. An Ubuntu web container, web01, has been deployed and configured to use Apache. Create a new website called containerhub and enable it as the default site. To check that everything has been configured successfully, create a temporary index.html page. Curl the page from the host.

Note: Please give this lab some extra time (2-3 minutes) to provision before connecting via ssh.

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?