Create and Deploy an Application Back End

2 hours
  • 5 Learning Objectives

About this Hands-on Lab

The goal for this lab is to create and deploy an application back end. We first need to create a container with a CentOS 7 image and then access it. Then, from within the container, we need to download, configure, and run the Flask application from GitHub where we will acquire two files: our service and ``. To do this, we need to install `git` on the container. After that, we will daemonize the process by downloading and modifying a service file for the Flask app. Next, we will install and configure the Apache web server for the virtual host to function as a reverse proxy to the application. Lastly, it’s important to verify the back end is accessible with `curl`.

Learning Objectives

Successfully complete this lab by achieving the following learning objectives:

Create a Container on the Server with the CentOS 7 Image and Access It
  1. Create a container with the CentOS 7 image.

    lxc launch images:centos/7/amd64 Backend
  2. Access the container.

    lxc exec Backend bash
Configure the Container
  1. Create a new backend user, then download, configure, and run the flask app from GitHub.

    useradd backend -m
    passwd backend
  2. Install prerequisites for the back-end application.

    yum install git vim
  3. Edit to set the database IP address and username.

    su backend
    cd /home/backend/
  4. Clone the GitHub file.

    git clone
    cp /home/backend/Containers/ .
    chmod 500 /home/backend/Containers/
    cp /home/backend/Containers/our-app.service .
    rm -rf /home/backend/Containers
  5. Install python36.

    yum install python36 python36-devel -y
    su backend
    pip3 install --user flask flask_cors mysql-connector waitress
  6. Change the IP address of the database to the IP address of the container, then close the file. We can get the IP address of the database container by executing lxc list on the host.

    vim /home/backend/
  7. Edit the file:

    • Change the IP of the database.
    • Change the username from chronic to cloud_user.
On the Container, Daemonize the Process and Create a Redirect on the Host
mkdir /home/backend/our-backend
cp /home/backend/our-app.service /etc/systemd/system/
mv /home/backend/ /home/backend/our-backend/
chown -R backend:backend our-backend/
chmod +x /home/backend/our-backend/
systemctl daemon-reload
systemctl start our-app
systemctl enable our-app  
lxc config device add Backend myport80 proxy listen=tcp: connect=tcp:BACKEND_IP:80
On the Container, Install and Configure Apache Web Server for a Virtual Host to Accept Connections on Port 80
lxc exec Backend bash
yum install httpd
systemctl start httpd
systemctl enable httpd
mkdir /etc/httpd/sites-enabled
mkdir /etc/httpd/sites-available
vim /etc/httpd/sites-available/
<VirtualHost *:80>
ProxyPass          /
ProxyPassReverse   /

        Require all granted
        Options None
vim /etc/httpd/conf/httpd.conf
IncludeOptional sites-enabled/*.conf
sudo ln -s /etc/httpd/sites-available/ /etc/httpd/sites-enabled/
systemctl restart httpd
Verify the Back End is Accessible with curl from a Playground Instance
  1. If curl is not installed, install it.

    sudo apt install curl


    sudo yum install curl
  2. Run the tests.

    curl http://server_ip/
    curl http://server_ip/random_number

Additional Resources

The MariaDB database is already up and running in an LXC container. We can verify it with the following command:

lxc list

This also indicates the IP of the database container. The credentials are as follows:

Username: cloud_user
Password: Test321
Database: MyDB 

We can download the needed code from the GitHub repository.

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?