Pull the Image from Docker Hub & Install Apache2 on a Separate Machine — Docker Assignment 3

Visal Tyagi
DevOps-Guides
Published in
5 min readApr 26, 2024

You have been asked to:

● Use the saved image in the previous assignment

● Upload this image on Dockerhub

● On a separate machine pull this docker hub image, and launch it on port 80

● Start the apache2 service

● Verify if you can see the apache2 service

Apache Default Page
Apache Default Page

Note: Check “Docker Assignment2 Solution” before performing the Docker Assignment2. Because it is an extensive solution of Docker Assignment 2.

Git Hub Repository Link for Docker Assignment 3 for Commands

A. Use the saved image in the previous assignment

Step 1: Go to “EC2 Console”, and rename the “assignment2” image as “visaltyagi12/assignment3”. Use this command:

sudo docker tag assignment2 visaltyagi12/assignment3
Rename the Image
Rename the Image

When you do “docker images”, a new repository will be created as “visaltyagi12/assignment3”.

B. Upload this image on Docker Hub

Step 1: Now, we will log in to our docker hub account using this command:

sudo docker login
Login Command
Login Command

Provide the “username and password” here. Login will be successful.

Step 2: Use the below command to push the image in Docker Hub.

sudo docker push visaltyagi12/assignment3
Push the Image
Push the Image

Step 3: Login into your Docker Hub Account & The repository will be shown as “visaltyagi12/assignment3”.

Docker Repository
Docker Repository

Step 4: Click on “visaltyagi12/assignment3”. All the information inside the image will be shown.

Assignment 3 Image
Assignment 3 Image

C. On a separate machine pull this docker hub image, and launch it on port 80

Step 1: Go to the “Services” section & put the cursor over “EC2”. Click on “Instances”.

Search EC2 Here
Search EC2 Here

Step 2: Click on “Launch Instance”.

Launch instance
Launch instance

Step 3: Choose “Name” as “Assignment3” in the “Name and tags” section.

Instance Name
Instance Name

Step 4: Choose “AMI” as “Ubuntu”.

Ubuntu AMI
Ubuntu AMI

Step 5: Choose “Instance type” as “t2.micro” & key pair(login) as “Docker”.

Instance type & keypair
Instance type & keypair

Step 6: Choose “Common security groups” as “launch-wizard-9”.

Choose Security Group
Choose Security Group

Step 7: Click on “Launch Instance”.

Launch Instance
Launch Instance

Step 8: Click on “hyperlink [i-08427f80dbcb807d6]”.

Click Hyperlink
Click Hyperlink

Step 9: The instance will be in the “Running State”. Select the Instance & click on “Connect”.

Connect
Connect

Step 10: Again, click on “Connect”.

Connect Again
Connect Again

Step 11: Update the machine using this command:

sudo apt-get update
Update Command
Update Command

Step 12: Install the docker using this command:

sudo apt-get install docker.io -y
Install docker
Install docker

Step 13: Login as a root user to access “Docker” using this command:

sudo su -
root user
root user

Step 14: Check the “Docker” status using this command:

systemctl status docker
Docker Status
Docker Status

Docker is in an “Active” state.

Step 15: First, we will pull the image from Docker Hub. Use this command:

sudo docker pull visaltyagi12/assignment3
Docker Image Pull
Docker Image Pull

Step 16: The image will be shown using the command:

docker images
View the Image
View the Image

The image will be successfully pulled.

Step 17: Now, we will create a container through this image on port no.80. Use this command:

docker container run –itd --name testcont –p 80:80 visaltyagi12/assignment3
docker container ls -a
docker container created
docker container created
Container
Container
Port
Port

When you do “docker container ls –a”, you will notice that the container is successfully created on port no. 80.

Step 7: Go inside the container using this command:

docker container exec -it testcont bash
Inside Container

Step 8: Run the “apt update’ command to update the machine. To install the apache2 in container use this command:

apt update
apt install apache2
Update
Update
Install Apache2
Install Apache2

Type “Y” & apache2 will be successfully installed.

D. Start the apache2 service

Step 1: Run these commands to check the status & start the apache2.

Command: “service apache2 start” for Starting Apache2.

Command: “service apache2 status” for Status Check

service apache2 start
service apache2 status
apache2 start
apache2 start

E. Verify if you can see the apache2 service

Step 1: To verify whether Apache2 is installed or not, Go to the “EC2 Instance” section, and select “Running Instance”.

Click on “Open Address” in “Public IPv4 Address”.

Click on Open Address
Click on Open Address

Step 2: A separate web page will be opened with the IP Address. It will show you the default Apache2 Web Page.

Apache Default Page
Apache Default Page

Other Docker Assignments:

Create a Container on Ubuntu & Install Apache2 on It — Docker Assignment 1

Containerized an HTML Website using Docker on Production Environment — Docker Case Study

Replace the Apache Default Web Page With Sample HTML File Inside Container — Docker Assignment 5

--

--