DEV Community

janak0ff
janak0ff

Posted on

KodeKloud - 100 Days of DevOps - Day 41: Write a Docker File

As per recent requirements shared by the Nautilus application development team, they need custom images created for one of their projects. Several of the initial testing requirements are already been shared with DevOps team. Therefore, create a docker file /opt/docker/Dockerfile (please keep D capital of Dockerfile) on App server 1 in Stratos DC and configure to build an image with the following requirements:

a. Use ubuntu:24.04 as the base image.

b. Install apache2 and configure it to work on 6000 port. (do not update any other Apache configuration settings like document root etc).


Step-by-Step Solution

Step 1: SSH to App Server 1

ssh tony@stapp01
# Password: Ir0nM@n
Enter fullscreen mode Exit fullscreen mode

Step 2: Switch to Root (if needed)

sudo su -
# Password: Ir0nM@n
Enter fullscreen mode Exit fullscreen mode

Step 3: Create the Directory

# Create the /opt/docker directory
mkdir -p /opt/docker

# Navigate to the directory
cd /opt/docker
Enter fullscreen mode Exit fullscreen mode

Step 4: Create the Dockerfile

# Create Dockerfile with capital D
vi Dockerfile
Enter fullscreen mode Exit fullscreen mode

Step 5: Add Content to Dockerfile

# Use ubuntu:24.04 as base image
FROM ubuntu:24.04

# Update package list and install apache2
RUN apt-get update && \
    apt-get install -y apache2 && \
    apt-get clean

# Expose port 6000
EXPOSE 6000

# Configure Apache to listen on port 6000
RUN sed -i 's/Listen 80/Listen 6000/g' /etc/apache2/ports.conf && \
    sed -i 's/:80>/:6000>/g' /etc/apache2/sites-available/000-default.conf

# Start Apache in foreground
CMD ["/usr/sbin/apache2ctl", "-D", "FOREGROUND"]
Enter fullscreen mode Exit fullscreen mode

📊 Verification Commands

Check Dockerfile:

# Check file exists
ls -la /opt/docker/Dockerfile

# View content
cat /opt/docker/Dockerfile
Enter fullscreen mode Exit fullscreen mode

Build and Test Image (Optional):

# Build the image
docker build -t apache2:6000 /opt/docker/

# Run the container
docker run -d --name apache2-test -p 6000:6000 apache2:6000

# Test Apache
curl http://localhost:6000

# Clean up
docker stop apache2-test
docker rm apache2-test
Enter fullscreen mode Exit fullscreen mode

✅ Task Summary

Requirement Status
SSH to App Server 1
Create /opt/docker directory
Create Dockerfile (capital D)
Use ubuntu:24.04 base image
Install apache2
Configure Apache port 6000
No other configuration changes

Top comments (0)