Cloud Native 5 Minutes at a Time: Running a Containerized App

Eric Gregory - March 29, 2022 - , ,

One of the biggest challenges for implementing cloud native technologies is learning the fundamentals—especially when you need to fit your learning into a busy schedule.

In this series, we’ll break down core cloud native concepts, challenges, and best practices into short, manageable exercises and explainers, so you can learn five minutes at a time. These lessons assume a basic familiarity with the Linux command line and a Unix-like operating system—beyond that, you don’t need any special preparation to get started.

In our last lesson, we defined some core concepts in container networking and learned how to publish container ports, opening a container’s services to traffic from the outside world. This time, we’re going to bring together most of what we’ve learned so far to run a containerized web app with persistent volumes and published ports: in this case, a knowledge-sharing wiki platform.

Table of Contents

  1. What is a Container?
  2. Creating, Observing, and Deleting Containers
  3. Build Image from Dockerfile
  4. Using an Image Registry
  5. Volumes and Persistent Storage
  6. Container Networking and Opening Container Ports
  7. Running a Containerized App←You are here
  8. Multi-Container Apps on User-Defined Networks
  9. Docker Compose and Next Steps

Bringing the pieces together

Wikipedia is built on an open source platform called Mediawiki, and an official Docker image for the application is maintained on Docker Hub. That means it should be easy to get our own wiki running quickly—in less than five minutes, even!

The default architecture for this deployment is very straightforward: a single container for the application, which can either write data to a volume all on its own—the default configuration—or work in tandem with a second container running a production-grade database—the option you would want to use if you were taking this wiki to production, pushing it live for real-world use.

In this lesson, we’re going to start with a single-container configuration—but we won’t stop there. Next time, we’ll also explore how to link containers for a more production-ready configuration.

But we’re getting ahead of ourselves. For now, let’s focus on getting our wiki up and running!

Exercise: A Wiki as a Containerized App

You can follow a version of this exercise in the video below.

Let’s start by creating a new volume that will store the persistent data for our wiki:

docker volume create wiki-data

Now we’re going to run a Docker container based on the official Mediawiki image. We’ll call our new container solo-wiki since it’s going to run in a single-container configuration. We’ll also publish a port so we can access the application on our host machine, and add our volume for persistent storage.

docker run --name solo-wiki -v wiki-data:/wiki-data -p 8000:80 -d mediawiki

Now when we visit localhost:8000 in our web browser, we should see a starting page for our wiki. But the app still needs to be set up. On the starting page, click “Complete the installation.”

Screenshot of the base wiki page in the Chrome browser.

Choose your language and Continue.

Screenshot of MediaWiki installation in the Google chrome window.

The installation should pass its environmental checks. Click Continue.

Screenshot of installation confirmation in the browser.

On the database configuration screen, choose SQLite and specify the directory linked to our volume for the data directory—in this case: wiki-data/

Then click Continue.

Screenshot of configuring settings

Now you’ll need to name the wiki and create a username and password for the administrator account. From here, you can go ahead and complete the installation.

Screenshot of configurations

You should get a congratulations screen which will automatically download a file called LocalSettings.php to your machine. If it doesn’t do this automatically, click the link.

Screenshot of installation confirmation

This file takes many of the settings you’ve chosen—the database type, server, and credentials, for example—and associates them with variables used by the larger app.

Now we need to put the LocalSettings.php file we’ve just downloaded onto our host machine and into the base directory for our wiki installation. There are a number of different ways we could do this—for now, let’s hop into the running container, peek under the hood, and add the file manually. We’ll open a shell session with:

docker exec -it solo-wiki bash

Note where we’ve landed and have a look around:

root@e9537d7c33e3:/var/www/html# ls -1a

This is where we want to put our LocalSettings.php file. One way we can do this is to open the file in a text editor on our host machine, copy the contents, then create a new file in the container:

touch LocalSettings.php

Download nano:

apt update
apt install nano

And paste in the contents. Once we’ve saved the file with CTRL-O and exited to the shell with CTRL-X, we can delete nano with apt remove nano. (This is being very assiduous about optimizing the footprint of our image, but it’s a good habit, and even small differences add up at scale.)

Now we’ve made some changes to the container filesystem itself—changes outside the persistent volume–so in a new terminal tab, we should commit the changes to a new image:

docker commit solo-wiki solo-wiki

Here we’re committing the state of the container named solo-wiki to a new image, also called solo-wiki. With the image saved locally, we can stop and delete the container we’ve been working with:

docker container stop solo-wiki
docker container rm solo-wiki

Now let’s create a new container from the image we just saved, using a command very similar to the first wiki container we ran:

docker run --name solo-wiki -v wiki-data:/wiki-data -p 8000:80 -d solo-wiki

The only thing that will be different this time is that we’re creating our new container from the solo-wiki base image we just committed, with a LocalSettings.php file included–and our volume already has configuration data inside.

When we navigate to localhost:8000 now, we should have a fully configured wiki:

Screenshot of the installed WikiMedia page in the browser.

I recommend logging in with your administrator account and making changes to the main page. If you stop and restart the container…

docker container stop solo-wiki
docker container start solo-wiki

…you should find that your changes have persisted.

Screenshot of Wikimedia being installed and edited in the browser.

Now we have a functional containerized app running from a single container. Next time, we’ll continue our survey of container fundamentals by exploring a multi-container configuration for the app.

From Virtualization to Containerization
Learn how to move from monolithic to microservices in this free eBook
Download Now
Radio Cloud Native – Week of May 11th, 2022

Every Wednesday, Nick Chase and Eric Gregory from Mirantis go over the week’s cloud native and industry news. This week they discussed: Docker Extensions Artificial Intelligence shows signs that it's reaching the common person Google Cloud TPU VMs reach general availability Google buys MobileX, folds into Google Cloud NIST changes Palantir is back, and it's got a Blanket Purchase Agreement at the Department of Health and Human …

Radio Cloud Native – Week of May 11th, 2022
Where do Ubuntu 20.04, OpenSearch, Tungsten Fabric, and more all come together? In the latest Mirantis Container Cloud releases!

In the last several weeks we have released two updates to Mirantis Container Cloud - versions 2.16 and 2.17, which bring a number of important changes and enhancements. These are focused on both keeping key components up to date to provide the latest functionality and security fixes, and also delivering new functionalities for our customers to take advantage of in …

Where do Ubuntu 20.04, OpenSearch, Tungsten Fabric, and more all come together? In the latest Mirantis Container Cloud releases!
Monitoring Kubernetes costs using Kubecost and Mirantis Kubernetes Engine [Transcript]

Cloud environments & Kubernetes are becoming more and more expensive to operate and manage. In this demo-rich workshop, Mirantis and Kubecost demonstrate how to deploy Kubecost as a Helm chart on top of Mirantis Kubernetes Engine. Lens users will be able to visualize their Kubernetes spend directly in the Lens desktop application, allowing users to view spend and costs efficiently …

Monitoring Kubernetes costs using Kubecost and Mirantis Kubernetes Engine [Transcript]
The Definitive Guide to Container Platforms
Mirantis Webstore
Purchase Kubernetes support
Getting started with Kubernetes part 2: Creating K8s objects with YAML

Thursday, December 30, 2021 at 10:00 AM PST