Write a Docker File


Write a Docker File

Task :

As per recent requirements shared by the Nautilus application development team, they need custom images created for one of their projects. Several of the initial testing requirements are already been shared with DevOps team. Therefore, create a docker file /opt/docker/Dockerfile (please keep D capital of Dockerfile) on App server 2 in Stratos DC and configure to build an image with the following requirements:

a. Use ubuntu as the base image.

b. Install apache2 and configure it to work on 5000 port. (do not update any other Apache configuration settings like document root etc).

Solution :

[steve@stapp02 ~]$ cd /opt/docker
[steve@stapp02 docker]$ sudo vi Dockerfile

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 steve: 

FROM ubuntu
ARG DEBIAN_FRONTEND=noninteractive
RUN apt-get update
RUN apt-get install apache2 -y
RUN sed -i "s/80/5000/g" /etc/apache2/ports.conf
CMD ["/usr/sbin/apache2ctl", "-D", "FOREGROUND", "-k", "start"]

[steve@stapp02 docker]$ sudo docker build -t my_container .
Sending build context to Docker daemon 2.048kB
Step 1/7 : FROM ubuntu
latest: Pulling from library/ubuntu
345e3491a907: Pull complete 
57671312ef6f: Pull complete 
5e9250ddb7d0: Pull complete 
Digest: sha256:cf31af331f38d1d7158470e095b132acd126a7180a54f263d386da88eb681d93
Status: Downloaded newer image for ubuntu:latest
---> 7e0aa2d69a15
Step 2/7 : ARG DEBIAN_FRONTEND=noninteractive
---> Running in e9cb10134e41
Removing intermediate container e9cb10134e41
---> b1feca1b48cf
Step 3/7 : RUN apt-get update
---> Running in 77eaf24d0477
Removing intermediate container 77eaf24d0477
---> c21501e03e8b
Step 4/7 : RUN apt-get install apache2 -y
---> Running in 3138f03de12c
Removing intermediate container 3138f03de12c
---> 0b630df99b43
Step 5/7 : RUN sed -i "s/80/5000/g" /etc/apache2/ports.conf
---> Running in ca828b0da497
Removing intermediate container ca828b0da497
---> 9330279210d4
Step 6/7 : EXPOSE 5000
---> Running in 06e6ae984196
Removing intermediate container 06e6ae984196
---> d44b25046f37
Step 7/7 : CMD ["/usr/sbin/apache2ctl", "-D", "FOREGROUND", "-k", "start"]
---> Running in 28dc3ccc4903
Removing intermediate container 28dc3ccc4903
---> d6ae4f305a44
Successfully built d6ae4f305a44
Successfully tagged my_container:latest
[steve@stapp02 docker]$ sudo docker run --name my_server -p 5000:5000 -d my_container
[steve@stapp02 docker]$ curl http://localhost:5000/

One thought on “Write a Docker File”

Leave a Reply

Your email address will not be published. Required fields are marked *