Day 45: Resolve Dockerfile Issues | 100 Days of DevOps
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, andCOPY, and how Docker processes commands during image creation.
๐น What I Learned
- How Dockerfile instructions work
- Difference between
FROM,RUN,ADD, andCOPY - 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/dockerEnsure 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:
FROMis 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:
ADDis used only for copying files/directories- It cannot execute Linux commands
RUNis used to execute commands during image build
๐ In simple terms:
ADD= copy filesRUN= 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
80to8080
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 imageRUNโ executes commandsCOPYโ copies filesADDโ 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