Docker Task

Ashutosh Rai
4 min readDec 1, 2021

--

Task 1:
— Set Up docker on AWS Ec2

— Launch a container with centos:7 image.
a) Install apache server (httpd) inside container.
b) Make sure you should check the html page on 8080 port.

Task 2:
— create a custom image that has apche server installed using Dockerfile.
Note: Take centos:7 as base image.

— Launch a container with custom image.
— Push the created image to Docker Hub.

— Create a volume in docker and mount it to container.
a) Create a folder in base OS and create some html files.
b) Mount the volume to /var/www/html

— — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — — —

Hello folks…

In this task we have to use docker in ec2 machine for that you have to first install docker in ec2 and setup also.. The cmd is:

  • sudo yum update -y
  • sudo amazon-linux-extras install docker (This is the cmd to install docker in ec2)
  • sudo service docker start (This cmd is to start the service)
  • systemctl status docker (This cmd is to check the service is start or not)
  • systemctl enable docker (This cmd is always started the service)

Now is the next step i.e we have to launch centos:7 on ec2 machine for that you have to pull centos:7 from official site docker i.e hub.docker.com. You can write directly command on ec2 machine it will download your image.

  • docker pull centos:7 (It will download the image from docker hub)
  • docker images (You can check your images is downloaded or not)

Now come to the next part i.e we have to install httpd inside container & we have to make sure that html page should be open only on 8080 port. For that what is the cmd & what is the purpose also.

  • docker run -dit -name ashuos -p 8080:80 centos:7 (-d → detach mode -p →patting on 8080 port )
  • docker exec -it ashuos bash ( This cmd help you to go inside the container)

And their you can install httpd. The cmd is…

  • yum install httpd -y (This cmd is to install apache)
  • cd /var/www/html (This is the default configuration file and server always see this file only)
  • vim index.html (vim is the default editor and index.html is the default page where you can write what you want to write)

Now go to chrome and paste public ip with the port number also

For example (http://publicip:port no)

Task 1 is completed,,,,,

…………………………………………………………………………………………

Now coming to the next part!!

According to Task 2 We have to create custom image that has apache server installed using Dockerfile & also the base image should be centos:7 only

You can go to default configuration file i.e /var/www/html

In there you can create Dockerfile

  • vim Dockerfile

FROM centos:7

RUN yum install httpd -y

EXPOSE 80

ENTRYPOINT [“/usr/sbin/httpd”,”-D”,”FOREGROUND”]

  • docker build -t rahul:v2 /var/www/html/ ( This cmd help you to build the image and you can also check )
  • docker images (In there you can check the image)

Now you have to launch the container using your own custom image that you have created

  • docker run -it -name ashutosh rahul:v2

The created image you have to upload to the hub.docker.com. How it’s possible the solution is:

First step you have to create repository in hub.docker.com

Second step you have to login in docker the cmd is

  • Docker login ( And give the credentials)

Third step you have to tag your image by using your default name of hub.docker.com and there repository i.e

  • docker tag rahul:v2 ashut1908/webserver:latest (rahul is your custom image and ashut1908 is your account name of docker hub)

Fourth step is to push custom image to hub.docker.com

  • docker push ashut1908/webserver:7 (ashut1908 is your account name of hub.docker.com and webserver is the repository name of hub.docker.com and 7 is the version)

Now is the last step but not the least

You have to create volume and mount it to /var/www/html

  • mkdir rahul (Directory of name)
  • cd rahul (you have go to that name)
  • vim index.html (vim is a editor and index.html is the default page in there you can write what ever you what)

Now go to root directory and run the downward command

  • docker run -dit — name myos -v /root/kushi:/var/www/html/ -p 8081:80 rahul:v2

Task 2 is completed,,,,,

Thankyou(….

…………………………………………………………………………………………

--

--