The Nautilus DevOps team is working to create new images per requirements shared by the development team. One of the team members is working to create a Dockerfile on App Server 1 in Stratos DC. While working on it she ran into issues in which the docker build is failing and displaying errors. Look into the issue and fix it to build an image as per details mentioned below:
a. The Dockerfile is placed on App Server 1 under /opt/docker directory.

b. Fix the issues with this file and make sure it is able to build the image.

c. Do not change base image, any other valid configuration within Dockerfile, or any of the data been used — for example, index.html.

Note: Please note that once you click on FINISH button all the existing containers will be destroyed and new image will be built from your Dockerfile.

Connect to App Server 1

ssh tony@stapp01 sudo -i 

Password for tony: Ir0nM@n

Inspect the Build Context

cd /opt/docker ls -la 

Output:

total 24 drwxrwxrwx 4 root root 4096 Oct 27 11:53 . drwxr-xr-x 1 root root 4096 Oct 27 11:53 .. -rw-r--r-- 1 root root 504 Oct 27 11:53 Dockerfile drwxr-xr-x 2 root root 4096 Oct 27 11:53 certs drwxr-xr-x 2 root root 4096 Oct 27 11:53 html 

The build context contains the Dockerfile, a certs/ directory, and an html/ directory.

Verify the actual file locations:

ls -la /opt/docker/certs/ ls -la /opt/docker/html/ 

Output:

total 16 drwxr-xr-x 2 root root 4096 Oct 27 11:53 . drwxrwxrwx 4 root root 4096 Oct 27 11:53 .. -rw-r--r-- 1 root root 1305 Oct 27 11:53 server.crt -rw-r--r-- 1 root root 1674 Oct 27 11:53 server.key total 12 drwxr-xr-x 2 root root 4096 Oct 27 11:53 . drwxrwxrwx 4 root root 4096 Oct 27 11:53 .. -rw-r--r-- 1 root root 22 Oct 27 11:53 index.html 

The certificate files are inside certs/ and the website file is inside html/.

View the Original Dockerfile

cat /opt/docker/Dockerfile 

Original 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 /server.crt /usr/local/apache2/conf/server.crt COPY /server.key /usr/local/apache2/conf/server.key COPY ./index.html /usr/local/apache2/htdocs/ 

Issues Identified

Line Issue
COPY /server.crt Absolute path /server.crt does not exist in the build context
COPY /server.key Absolute path /server.key does not exist in the build context
COPY ./index.html index.html is not in the build context root; it is inside html/
conf/httpd.conf Relative path used instead of full path for consistency

Fix the Dockerfile

Edit the file:

vi /opt/docker/Dockerfile 

Corrected 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' /usr/local/apache2/conf/httpd.conf RUN sed -i '/LoadModule\ socache_shmcb_module modules\/mod_socache_shmcb.so/s/^#//g' /usr/local/apache2/conf/httpd.conf RUN sed -i '/Include\ conf\/extra\/httpd-ssl.conf/s/^#//g' /usr/local/apache2/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/ 

Verify the corrected file:

cat /opt/docker/Dockerfile 

Output:

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' /usr/local/apache2/conf/httpd.conf RUN sed -i '/LoadModule\ socache_shmcb_module modules\/mod_socache_shmcb.so/s/^#//g' /usr/local/apache2/conf/httpd.conf RUN sed -i '/Include\ conf\/extra\/httpd-ssl.conf/s/^#//g' /usr/local/apache2/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/ 

Build the Image

cd /opt/docker docker build -t custom-httpd:latest . 

Output:

[+] Building 11.1s (13/13) FINISHED docker:default => [internal] load build definition from Dockerfile 0.1s => => transferring dockerfile: 614B 0.0s => [internal] load metadata for docker.io/library/httpd:2.4.43 1.3s => [internal] load .dockerignore 0.1s => => transferring context: 2B 0.0s => [1/8] FROM docker.io/library/httpd:2.4.43@sha256:cd88fee4eab37f0d8cd04b06ef97285ca981c27b 4.9s => => resolve docker.io/library/httpd:2.4.43@sha256:cd88fee4eab37f0d8cd04b06ef97285ca981c27b 0.1s => => sha256:b5fc3125d9129e4cdd43f496195cc8f39d43e9bad171044ecb5b8f82b2f6e 10.37MB / 10.37MB 0.5s => => sha256:cd88fee4eab37f0d8cd04b06ef97285ca981c27b4d685f0321e65c5d4fd4935 1.86kB / 1.86kB 0.0s => => sha256:53729354a74c9c146aa8726a8906e833755066ada1a478782f4dfb2ea6994b5 1.37kB / 1.37kB 0.0s => => sha256:f1455599cc2e008a4555f14451e590f071371d371a3b87790651a367357d252 7.35kB / 7.35kB 0.0s => => sha256:bf59529304463f62efa7179fa1a32718a611528cc4ce9f30c0d1bbc6724ec 27.09MB / 27.09MB 0.6s => => sha256:3d3fecf6569b94e406086a2b68a7c8930254490b45c0de4911f497ea9cf0876c 146B / 146B 0.5s => => extracting sha256:bf59529304463f62efa7179fa1a32718a611528cc4ce9f30c0d1bbc6724ec3fb 1.1s => => sha256:34b7e9053f76ca3c9dc574c5034679769256a596008efbfbff1d1b1546600841 298B / 298B 0.8s => => sha256:3c61041685c0f65e0b375bae6ae6bdeab9b6c20960dbef5e30201db18a4e6 24.47MB / 24.47MB 1.1s => => extracting sha256:3d3fecf6569b94e406086a2b68a7c8930254490b45c0de4911f497ea9cf0876c 0.0s => => extracting sha256:b5fc3125d9129e4cdd43f496195cc8f39d43e9bad171044ecb5b8f82b2f6e30d 0.6s => => extracting sha256:3c61041685c0f65e0b375bae6ae6bdeab9b6c20960dbef5e30201db18a4e6d4a 0.8s => => extracting sha256:34b7e9053f76ca3c9dc574c5034679769256a596008efbfbff1d1b1546600841 0.1s => [internal] load build context 0.1s => => transferring context: 3.19kB 0.0s => [2/8] RUN sed -i "s/Listen 80/Listen 8080/g" /usr/local/apache2/conf/httpd.conf 0.4s => [3/8] RUN sed -i '/LoadModule\ ssl_module modules\/mod_ssl.so/s/^#//g' /usr/local/apache2 0.4s => [4/8] RUN sed -i '/LoadModule\ socache_shmcb_module modules\/mod_socache_shmcb.so/s/^#//g 0.4s => [5/8] RUN sed -i '/Include\ conf\/extra\/httpd-ssl.conf/s/^#//g' /usr/local/apache2/conf/ 0.4s => [6/8] COPY certs/server.crt /usr/local/apache2/conf/server.crt 0.2s => [7/8] COPY certs/server.key /usr/local/apache2/conf/server.key 0.2s => [8/8] COPY html/index.html /usr/local/apache2/htdocs/ 0.2s => exporting to image 2.2s => => exporting layers 2.1s => => writing image sha256:5e09aa4b303916f8711b6a5fe65a7ec15b14ae21d15e12ee326d17930ef3fc64 0.0s => => naming to docker.io/library/custom-httpd:latest 0.0s 

The build completed successfully with all 13 steps finished.

Verify the Image

docker images | grep custom-httpd 

Output:

custom-httpd latest 5e09aa4b3039 5 seconds ago 166MB 

The image custom-httpd:latest was built successfully.

Complete Command Sequence

ssh tony@stapp01 sudo -i cd /opt/docker ls -la ls -la /opt/docker/certs/ ls -la /opt/docker/html/ cat /opt/docker/Dockerfile vi /opt/docker/Dockerfile # Fix the COPY paths cat /opt/docker/Dockerfile docker build -t custom-httpd:latest . docker images | grep custom-httpd