Resolve Dockerfile Issues

Ticker

6/recent/ticker-posts

Resolve Dockerfile Issues

Question : 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 existing images, the containers will be destroyed and new image will be built from your Dockerfile.

 Please Note :-  Perform the below commands based on your question server,  user name & other details that might differ. So please read the task carefully before executing it. 
All the Best 👍

Solution:  

 1.  Login on app server  as per the task & Switch to  root user 

thor@jump_host ~$ ssh tony@stapp01

The authenticity of host 'stapp01 (172.16.238.10)' can't be established.

ECDSA key fingerprint is SHA256:fWEtFckVapXTPdlpN2mujI7VfUS61yk+XOq+rBbwvQQ.

ECDSA key fingerprint is MD5:cf:59:f7:4f:7a:e9:fa:3a:7b:d3:c4:ff:c6:c7:9a:ed.

Are you sure you want to continue connecting (yes/no)? yes

Warning: Permanently added 'stapp01,172.16.238.10' (ECDSA) to the list of known hosts.

tony@stapp01's password:

[tony@stapp01 ~]$ sudo su -

We trust you have received the usual lecture from the local System

Administrator. It usually boils down to these three things:

    #1) Respect the privacy of others.

    #2) Think before you type.

    #3) With great power comes great responsibility.

[sudo] password for tony:

[root@stapp01 ~]#

2. Run the below command to check existing docker images 

root@stapp01 ~]# docker images

REPOSITORY   TAG       IMAGE ID   CREATED   SIZE

[root@stapp01 ~]#

3.  Edit vi Dockerfile  under /opt/docker directory Refer Video post below )

    Kindly replace directives (IMAGE with FROM and ADD with RUN) 
    

[root@stapp01 ~]# cd /opt/docker

[root@stapp01 docker]# vi Dockerfile

[root@stapp01 docker]# cat 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' /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/

[root@stapp01 docker]#


4.  Build an image using this Dockerfile 

[root@stapp01 docker]# docker build -t httpd_image .

Sending build context to Docker daemon  9.216kB

Step 1/8 : FROM httpd:2.4.43

2.4.43: Pulling from library/httpd

bf5952930446: Pull complete

3d3fecf6569b: Pull complete

b5fc3125d912: Pull complete

3c61041685c0: Pull complete

34b7e9053f76: Pull complete

Digest: sha256:cd88fee4eab37f0d8cd04b06ef97285ca981c27b4d685f0321e65c5d4fd49357

Status: Downloaded newer image for httpd:2.4.43

 ---> f1455599cc2e

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

 ---> Running in 45063dc65604

Removing intermediate container 45063dc65604

 ---> 09bd9755cfaa

Step 3/8 : RUN sed -i '/LoadModule\ ssl_module modules\/mod_ssl.so/s/^#//g' /usr/local/apache2/conf/httpd.conf

 ---> Running in 648760d30831

Removing intermediate container 648760d30831

 ---> de6b024890be

Step 4/8 : RUN sed -i '/LoadModule\ socache_shmcb_module modules\/mod_socache_shmcb.so/s/^#//g'  /usr/local/apache2/conf/httpd.conf

 ---> Running in 3416bae86d9d

Removing intermediate container 3416bae86d9d

 ---> 3942c7f4cf11

Step 5/8 : RUN sed -i '/Include\ conf\/extra\/httpd-ssl.conf/s/^#//g' /usr/local/apache2/conf/httpd.conf

 ---> Running in a09bc65333bd

Removing intermediate container a09bc65333bd

 ---> 3c91a7b7f7e7

Step 6/8 : COPY certs/server.crt /usr/local/apache2/conf/server.crt

 ---> 391d11b244d6

Step 7/8 : COPY certs/server.key /usr/local/apache2/conf/server.key

 ---> c5103b38aa92

Step 8/8 : COPY html/index.html /usr/local/apache2/htdocs/

 ---> 94b87dd5abf9

Successfully built 94b87dd5abf9

Successfully tagged httpd_image:latest

[root@stapp01 docker]#


5.  Validate the task by docker images & run the container 

[root@stapp01 docker]# docker images

REPOSITORY    TAG       IMAGE ID       CREATED              SIZE

httpd_image   latest    94b87dd5abf9   About a minute ago   166MB

httpd         2.4.43    f1455599cc2e   12 months ago        166MB

[root@stapp01 docker]#


6.  Click on Finish & Confirm to complete the task successful

Happy Learning!!!!


Apart from this if you need more clarity,  I have made a  tutorial video on this , please go through and share your comments. Like and share the knowledge




Post a Comment

0 Comments

Latest Posts

KodeKloud Kubernetes Security CKS  Lab Challenge 4 |  Audit-policy | Install & configure falco utility | Inspect the API server audit logs and identify the user