How to Create an Apache Web Server with Docker on Ubuntu 24.04

This blog demonstrates how to build a Dockerfile using Ubuntu 24.04 as the base image to provision an Apache Web Server, configure it for deployment, and expose port 80 for HTTP access.

Create Dockerfile

# Use Ubuntu 24.04 as base
FROM ubuntu:24.04  

# Install Apache
RUN apt-get update && apt-get install -y apache2 && apt-get clean  

# Copy custom HTML content (optional)
# COPY ./index.html /var/www/html/index.html

# Expose port 80
EXPOSE 80  

# Start Apache in foreground
CMD ["apachectl", "-D", "FOREGROUND"]

Buin an Image

docker build -t apache-ubuntu24 .

Run the Container

docker run -d -p 8080:80 apache-ubuntu24

Now open http://localhost:8080 in your browser to view the Apache server.

Leave a Reply

Your email address will not be published. Required fields are marked *