Pull the Image from Docker Hub & Install Apache2 on a Separate Machine — Docker Assignment 3
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
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
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
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
Step 3: Login into your Docker Hub Account & The repository will be shown as “visaltyagi12/assignment3”.
Step 4: Click on “visaltyagi12/assignment3”. All the information inside the image will be shown.
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”.
Step 2: Click on “Launch Instance”.
Step 3: Choose “Name” as “Assignment3” in the “Name and tags” section.
Step 4: Choose “AMI” as “Ubuntu”.
Step 5: Choose “Instance type” as “t2.micro” & key pair(login) as “Docker”.
Step 6: Choose “Common security groups” as “launch-wizard-9”.
Step 7: Click on “Launch Instance”.
Step 8: Click on “hyperlink [i-08427f80dbcb807d6]”.
Step 9: The instance will be in the “Running State”. Select the Instance & click on “Connect”.
Step 10: Again, click on “Connect”.
Step 11: Update the machine using this command:
sudo apt-get update
Step 12: Install the docker using this command:
sudo apt-get install docker.io -y
Step 13: Login as a root user to access “Docker” using this command:
sudo su -
Step 14: Check the “Docker” status using this command:
systemctl status docker
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
Step 16: The image will be shown using the command:
docker images
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
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
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
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
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”.
Step 2: A separate web page will be opened with the IP Address. It will show you the default Apache2 Web 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