Deploy Apache Web Server Using Docker: A Step-by-Step Guide
๐ Install and Run Apache Web Server Using Docker
This guide explains how to install Docker, pull an Apache image, create a container, start it, and verify that Apache is running successfully.
๐ Prerequisites
- Linux server (RHEL / Amazon Linux / Ubuntu)
- Docker installed and running
- Root or sudo access
Step 1️⃣ Install Docker
For RHEL / Amazon Linux
sudo yum install -y docker sudo systemctl start docker sudo systemctl enable docker sudo systemctl status docker
Verify Docker Installation
docker --version docker info
Step 2️⃣ Pull the Apache Docker Image
docker pull ubuntu/apache2:2.4-20.04_beta
Step 3️⃣ Create the Apache Container
Create a container named apache2 and map port 80 from the container to the host.
docker create \ --name apache2 \ -p 80:80 \ ubuntu/apache2:2.4-20.04_beta
Verify Container Creation
docker ps -a
Step 4️⃣ Start the Container
docker start apache2
Verify Running Container
docker ps
Step 5️⃣ Verify Apache Service
Option 1: Test from the Server
curl http://localhost
Option 2: Test from Browser
http://<SERVER-IP>
✅ You should see the Apache default welcome page, confirming that Apache is running
successfully inside the Docker container.
๐งน Useful Docker Commands
docker stop apache2 docker start apache2 docker restart apache2 docker logs apache2 docker rm apache2
๐ฏ Conclusion
You have successfully installed Docker, created and started an Apache container, and verified the service. This approach is ideal for quick deployments, testing, and learning Docker fundamentals.
Comments
Post a Comment