Skip to main content

Command Palette

Search for a command to run...

Day 45: Resolve Dockerfile Issues | 100 Days of DevOps

Updated
โ€ข4 min read
R
Iโ€™m currently working in DevOps and documenting my learning journey along the way. From CI/CD pipelines to cloud and containers, Iโ€™m exploring how modern systems are built and deployed. This blog is where I share what I learn, break down concepts in simple terms, and track my progress. Learning one concept at a time, and trying to apply it practically.

Content:

Today I worked on troubleshooting and fixing Dockerfile errors on App Server 3. The Docker image build was failing because of incorrect Dockerfile instructions. The task helped me understand the difference between Dockerfile instructions like FROM, RUN, ADD, and COPY, and how Docker processes commands during image creation.


๐Ÿ”น What I Learned

  • How Dockerfile instructions work
  • Difference between FROM, RUN, ADD, and COPY
  • How to troubleshoot Docker build errors
  • How to identify Dockerfile syntax issues

๐Ÿ”น Task Requirement

As per the Nautilus DevOps team requirements, I needed to:

  • Fix issues in the Dockerfile placed under /opt/docker

  • Ensure Docker image builds successfully

  • Avoid changing:

    • Base image
    • Existing valid configurations
    • Existing application data/files like index.html

๐Ÿ”น Steps I Followed

1. Connected to Application Server 3

ssh banner@stapp03

2. Navigated to Docker Directory

cd /opt/docker/

Checked available files:

ls

Output:

Dockerfile  certs  html

๐Ÿ‘‰ This confirmed:

  • Dockerfile is present
  • SSL certificates are available
  • HTML application files are available

3. Inspected the Existing Dockerfile

Command used:

cat Dockerfile

Observed Dockerfile content:

IMAGE httpd:2.4.43

ADD sed -i "s/Listen 80/Listen 8080/g" /usr/local/apache2/conf/httpd.conf

ADD sed -i '/LoadModule\ ssl_module modules\/mod_ssl.so/s/^#//g' conf/httpd.conf

ADD sed -i '/LoadModule\ socache_shmcb_module modules\/mod_socache_shmcb.so/s/^#//g' conf/httpd.conf

ADD sed -i '/Include\ conf\/extra\/httpd-ssl.conf/s/^#//g' conf/httpd.conf

COPY certs/server.crt /usr/local/apache2/conf/server.crt

COPY certs/server.key /usr/local/apache2/conf/server.key

COPY html/index.html /usr/local/apache2/htdocs/

๐Ÿ”น Problem Observed

Tried building the image:

docker build .

Docker returned error:

ERROR: failed to solve: dockerfile parse error on line 1: unknown instruction: IMAGE

๐Ÿ”น Problem Analysis

I identified two major issues in the Dockerfile.


Issue 1: Wrong Dockerfile Instruction (IMAGE)

Wrong:

IMAGE httpd:2.4.43

Correct:

FROM httpd:2.4.43

Explanation:

  • FROM is the correct Dockerfile instruction used to define the base image
  • Docker does not recognize IMAGE
  • Because of this, Docker build failed immediately

๐Ÿ‘‰ In simple terms:

Docker needs FROM to know which base operating system or application image should be used.


Issue 2: Wrong Usage of ADD

Wrong:

ADD sed -i ...

Correct:

RUN sed -i ...

Explanation:

  • ADD is used only for copying files/directories
  • It cannot execute Linux commands
  • RUN is used to execute commands during image build

๐Ÿ‘‰ In simple terms:

  • ADD = copy files
  • RUN = execute commands

๐Ÿ”น Steps Taken to Fix the Dockerfile

Opened Dockerfile for editing:

vi Dockerfile

Updated Dockerfile content:

FROM httpd:2.4.43

RUN sed -i "s/Listen 80/Listen 8080/g" /usr/local/apache2/conf/httpd.conf

RUN sed -i '/LoadModule\ ssl_module modules\/mod_ssl.so/s/^#//g' conf/httpd.conf

RUN sed -i '/LoadModule\ socache_shmcb_module modules\/mod_socache_shmcb.so/s/^#//g' conf/httpd.conf

RUN sed -i '/Include\ conf\/extra\/httpd-ssl.conf/s/^#//g' conf/httpd.conf

COPY certs/server.crt /usr/local/apache2/conf/server.crt

COPY certs/server.key /usr/local/apache2/conf/server.key

COPY html/index.html /usr/local/apache2/htdocs/

Saved and exited the file.


๐Ÿ”น Understanding the Correct Dockerfile

FROM

FROM httpd:2.4.43

Uses Apache HTTP Server image version 2.4.43 as the base image.


RUN Commands

Example:

RUN sed -i "s/Listen 80/Listen 8080/g" /usr/local/apache2/conf/httpd.conf

What it does:

  • Modifies Apache configuration
  • Changes Apache listening port from 80 to 8080

Other RUN commands:

  • Enable SSL module
  • Enable shared memory cache module
  • Enable SSL configuration include file

๐Ÿ‘‰ These commands customize Apache during image build.


๐Ÿ”น Rebuilt the Docker Image

Command used:

docker build -t apache-img .

Observed:

  • Docker image built successfully
  • No syntax errors
  • Build completed successfully

Docker generated image:

apache-img

๐Ÿ”น Verified Docker Images

Command used:

docker images

Observed:

REPOSITORY   TAG       IMAGE ID       SIZE
apache-img   latest    53ad9f724d81   166MB

๐Ÿ‘‰ This confirmed:

  • Image exists successfully
  • Build process completed properly

๐Ÿ”น My Understanding

This task helped me understand how sensitive Dockerfiles are to instruction names. Even a small mistake like using IMAGE instead of FROM causes the entire build to fail.

I also clearly understood the purpose of:

  • FROM โ†’ defines base image
  • RUN โ†’ executes commands
  • COPY โ†’ copies files
  • ADD โ†’ copies/extracts files but not for executing commands

๐Ÿ”น What I Found Interesting

I found it interesting that Docker builds images layer by layer, and every Dockerfile instruction creates a separate image layer.

Another important takeaway was understanding how configuration changes can be automated directly during image build using RUN commands.

This task also improved my troubleshooting skills because I had to:

  • Read Docker errors carefully
  • Identify invalid instructions
  • Replace them with proper Dockerfile commands
  • Rebuild and verify the image successfully

๐Ÿ“Œ Full notes: GitHub link

More from this blog

Rajesh's blog

85 posts