Unleashing the Docker Whale: Setting Up Apache2 on an Ubuntu Container

Brittany Jones
6 min readJul 7, 2023

--

Introduction

Hello! I am back again with another tutorial. In this article, we will explore the process of installing and configuring the Apache2 web server on an Ubuntu Docker container. We will embark on a journey on the Docker seas that combines the flexibility and isolation provided by Docker containers with the widely used Apache2 web server, creating an environment that streamlines web server deployment.

What is Docker?

Docker is a software platform that allows you to package and run applications in isolated environments called containers. It simplifies the process of deploying and managing applications by providing a consistent and portable environment across different operating systems and computing environments. With Docker, you can package an application into a container, ensuring that it runs consistently and reliably across different systems.

Objectives

  1. Run a Docker Ubuntu container running detached and on port 80.
  2. Use BASH shell to update all packages within the container.
  3. Use BASH to install Apache2 on the Ubuntu container.
  4. Add a custom webpage.
  5. Verify you can reach the webserver from your browser.

Prerequisites

  • Computer with stable internet connection
  • Remote terminal
  • AWS Management Console
  • Visual Studio Code Account
  • Docker Hub Account

Key Terms

  • Docker- a software platform that allows you to package and run applications in isolated environments called containers.
  • Ubuntu- a popular and widely used Linux-based, open-source operating system.
  • Apache2- a widely used open-source web server software.
  • Amazon Management Console- the browser-based graphical user interface for Amazon Web Services.
  • Visual Code Studio- a free and open-source code editor that is widely used by developers for various programming languages and frameworks.
  • Docker Hub- Docker Hub is a cloud-based registry service provided by Docker that allows users to store and share Docker container images.
  • Docker Image- a file used to execute code in a Docker container.
  • EC2 Instance- EC2 stands for Elastic Compute Cloud. It is an on-demand computing service provided by AWS.

Now that we have gone over the basics, let’s get into it!

For the purpose of this article, we will assume that Amazon Management Console and Visual Studio Code Account have already been set up. If assistance is needed for account creation, please refer to the following links:

1. Run a Docker Ubuntu container running detached and on port 80.

Our first objective is to run a Docker Ubuntu container running detached and on port 80. Before this is done, we must install Docker onto our remote terminal. I am working on Windows, so I used Windows Powershell to SSH from my EC2 instance in AWS to download Docker.

The next step is to connect to our remote terminal in Visual Studio Code.

Once connected to the terminal, we can get information about the version of Docker that we have installed.

Next, we will head over to Docker Hub to pull the Docker official Ubuntu image. You can copy the command directly from the site.

Paste the command directly into the terminal.

As you can see it pulls the “latest” up to date image.

Next, we will run our docker container as directed, detached and on port 80.

We can use the following command to retrieve the id, name, and status of the container that we recently created. This command will also give the information of all containers currently running on your system.

As you can see our container is up and running on port 80.

2. Use BASH shell to update all packages within the container.

Our second objective is to use BASH shell to update all packages within the container. This is achieved by entering the following command into the terminal:

This command places you inside of the container’s shell. The following command will update all packages within the container.

Great! All packages have been updated.

3. Use BASH to install Apache2 on the Ubuntu container.

The third objective is to use BASH to install Apache2 on the Ubuntu container. While still inside the shell of our container, we will enter the following command to install Apache2:

Yes! Apache2 has been successfully installed.

4. Add a custom webpage.

Our fourth objective is to add a custom webpage. We will first install our text editor. My text editor of choice is vim. The following command will install vim onto our container. Note that we are still inside of our shell.

Next, we will “cd” change directory into the /var/www/html/ directory to modify our webpage.

The following command will allow us to modify the webpage:

This will open the text editor.

The next step is to start the Apache2 service with the following command:

To check the status of Apache2 we will run this command:

Awesome! Apache2 is running.

5. Verify you can reach the webserver from your browser.

Now it’s time to see if all our hard work has paid off! The final objective is to verify if the webserver can be reached from our browser. This is done by retrieving the public IP address from our EC2 instance and entering it into our browser.

It’s works! Congratulations! We did it!!!!

Stay tuned and make sure to follow me as I will be posting more projects to document my journey into DevOps!

--

--