Create a Docker File Which Installs Apache2 Automatically After Running the Container— Docker Assignment 4
You have been asked to:
A. Create a Docker file with the following specs:
● Ubuntu container
● Apache2 installed
● Apache2 should automatically run once the container starts
B. Submit the Docker file, for assignment completion.
Before Checking this Assignment Solution, kindly check these assignment solutions before:
Create a Container on Ubuntu & Install Apache2 on It — Docker Assignment 1
Launch a Container Using a New Image & Start Apache 2 Sevice Here — Docker Assignment 2
Pull the Image from Docker Hub & Install Apache2 on a Separate Machine — Docker Assignment 3
Git Hub Repository Link for Copying the Commands
Problem (A) Solution: Create a Docker File Using the Given Specs
● Ubuntu container
● Apache2 installed
● Apache2 should automatically run once the container starts
A. First, Launch the New EC2 Instance as Assignment 4
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 “Assignment 4” in the “Name and tags” section.
Step 4: Choose “AMI” as “Ubuntu”.
Ubuntu AMI
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-041c3e5b59ce92d00)”.
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.
B. Create a Docker File
Step 1: Create a docker file using the command:
vim Dockerfile
Step 2: Write the following commands in the Dockerfile to create the container & automatically start Apache2.
FROM ubuntu
RUN apt-get update
RUN apt-get install apache2 -y
RUN apt-get install apache2-utils -y
RUN apt-get clean
ENTRYPOINT apache2ctl -D FOREGROUND
Do :wq! To save and quit the file. Your Dockerfile will be saved with these instructions.
Step 3: Now, we will create a new image using this Docker file using this command: “docker build –t assignment4 .” We use . because the docker file is present in the same directory.
sudo docker build -t assignment4 .
Step 4: When we run the “docker images” command. It will show the created image as “assignment4”.
docker images
Step 5: Now, we will create a container using the command:
docker container run –itd –p 80:80 - name testcont assignment4
The container named “ubuntu” was created successfully. You can check the container creation details using the command:
docker container ls -a
Step 6: Go to Instance. Select the Instance & click on “open address” in “Public IPv4 address”.
Step 7: Put :80 behind the IP Address & you will get the by default Apache2 Web Page.
B. Submit the Dockerfile for assignment completion
Dockerfile Content
FROM ubuntu
RUN apt-get update
RUN apt-get install apache2 -y
RUN apt-get install apache2-utils -y
RUN apt-get clean
ENTRYPOINT apache2ctl -D FOREGROUND
Read these Docker Guides
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