Fixing Docker Build Errors
I successfully completed the task of fixing a Dockerfile on App Server 2 to build a new image as per development requirements. The process involved identifying and correcting syntax errors in the Dockerfile and then troubleshooting a network connectivity issue during the build.
Steps and Outputs
1. Initial Problem Analysis
The user's initial attempt to build the Docker image failed due to several syntax errors in the original Dockerfile.
Original Dockerfile with Issues:
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/
-
IMAGE httpd:2.4.43
is incorrect; the correct directive isFROM
. - The
sed
commands were incorrectly prefixed withADD
.ADD
is used for adding files or directories to the image. To run shell commands, theRUN
directive is required.
2. Correcting the Dockerfile
I edited the Dockerfile (/opt/docker/Dockerfile
) to fix the syntax.
Corrected Dockerfile:
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/
3. Initial Build Attempt and Network Error
After the syntax was corrected, the first build attempt still failed due to a network timeout. The Docker client could not pull the base image from the configured registry mirror.
Command:
docker build -t httpd_image .
Output:
...
=> ERROR [internal] load metadata for docker.io/library/httpd:2.4.43 61.0s
...
ERROR: failed to build: failed to solve: DeadlineExceeded: ... dial tcp 10.0.0.6:443: i/o timeout
4. Resolving the Network Issue
To work around the timeout, I manually pulled the base image. This action caches the image locally, allowing the subsequent docker build
command to use the local copy instead of trying to download it again from the network.
Command:
docker pull httpd:2.4.43
Output:
2.4.43: Pulling from library/httpd
...
Status: Downloaded newer image for httpd:2.4.43
docker.io/library/httpd:2.4.43
5. Final Successful Build
With the base image now available locally, the final build command executed successfully.
Command:
docker build -t httpd_image .
Output:
[+] Building 8.6s (13/13) FINISHED ...
...
=> [1/8] FROM docker.io/library/httpd:2.4.43 0.0s
...
=> [8/8] COPY html/index.html /usr/local/apache2/htdocs/ 0.6s
=> exporting to image 2.2s
=> => exporting layers ...
=> => naming to docker.io/library/httpd_image 0.0s
The final output confirms that the Docker build process was able to successfully create the new image by executing all the steps specified in the corrected Dockerfile.
Top comments (0)