DEV Community

Wycliffe A. Onyango
Wycliffe A. Onyango

Posted on

100 Days of DevOps: Day 40

Configuring Apache2 in a Minimal Container

This article outlines the process of configuring the Apache2 web server within a containerized environment, specifically a minimal Ubuntu container named kkloud. It details the steps taken to install the service, change its default listening port, and verify its operational status, all while navigating the challenges of a stripped-down container image that lacks common utilities.


Step 1: Accessing the Container and Initial Setup

The first step was to establish a shell session inside the kkloud container, which was running on App Server 2. The docker ps -a command was used to list all containers, confirming the presence of the kkloud container. Following this, the docker exec -it kkloud bash command provided an interactive shell.

Once inside the container, the package lists were updated using apt-get update to ensure that the latest package information was available for installation.


Step 2: Installing and Configuring Apache2

With the package list updated, Apache2 was installed using the command apt-get install -y apache2. This command automatically installed Apache2 and its dependencies.

A key requirement of the task was to change the default listening port from 80 to 8082. This required modifying two core Apache configuration files:

  • /etc/apache2/ports.conf: The Listen 80 directive was changed to Listen 8082.
  • /etc/apache2/sites-available/000-default.conf: The <VirtualHost *:80> entry was updated to <VirtualHost *:8082>.

Since the container's minimal ubuntu:18.04 image lacked common text editors like vi, vim, or nano, the nano editor had to be installed first using apt-get install -y nano.


Step 3: Starting the Service and Overcoming Challenges

After making the configuration changes, the Apache service was started using apachectl start. During this process, a common warning appeared: "Could not reliably determine the server's fully qualified domain name". This warning is a standard informational message and does not prevent Apache from running.

The final and most crucial step was to verify that the service was running and correctly listening on the new port. Initially, the ss command was attempted, but it was not available in the container. Similarly, the netstat command also failed.

To resolve this, the iproute2 package was installed using apt-get install -y iproute2, which provides the ss command. After the installation, the ss -tlpn | grep 8082 command was executed, and the output confirmed success.

The output LISTEN 0 511 0.0.0.0:8082 0.0.0.0:* users:(("apache2",pid=3778,fd=3),...) confirmed that the Apache process was successfully listening on port 8082 across all network interfaces (0.0.0.0). . This final check validated that the entire task was completed successfully.

Top comments (0)