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

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

You have been asked to:

● Pull the Ubuntu image

● Create a container using Ubuntu, and map port 80 on the local

● Install apache2 on this container

● Check if you can access the Apache page on your browser

Apache2 Web Page
Apache2 Web Page

Git Hub Repository Link for Copy the Commands:

A. Pull Ubuntu Container

Step 1: Create an EC2 Instance First with Ubuntu Machine. Click on “EC2”.

EC2
EC2

Step 2: Click on “Instances (running)”.

Instances (running)
Instances (running)

Step 3: Click on “Launch Instances”.

Launch Instance
Launch Instance

Step 4: In “Name and Tags”, put “Name” as “Docker Assignment”.

Docker Assignment
Docker Assignment

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

Ubuntu AMI
Ubuntu AMI

Step 6: Remain “Instance type” as “t2.micro” & choose “key pair (login)” as “Proceed without a key pair (Not recommended)”.

Instance Type & Key pair (login)
Instance Type & Key pair (login)

Step 7: In “Network Settings”, choose Firewall (security groups)” as “Create security group”.

Create security group
Create security group

Tick the “Allow HTTP Traffic from the Internet” option to access the web page online.

Allow HTTP Traffic from the Internet
Allow HTTP Traffic from the Internet

Step 8: Click on “Launch Instance”.

Launch Instance
Launch Instance

Step 9: The instance will be launched successfully. Click on the hyperlink.

Click Hyperlink
Click Hyperlink

Step 10: Select the Instance & click on “Connect”.

Click Connect
Click Connect

Step 11: Again, click on “Connect”.

Connect Again
Connect Again

Step 12: Run the “sudo apt update” command to update the “Ubuntu” machine.

sudo apt update
Update Command
Update Command

Step 13: Install “Docker” using the “sudo apt-get install docker.io -y” command.

sudo apt-get install docker.io -y
Docker Installation Command
Docker Installation Command

Step 14: Access the docker by running the “sudo su –“ command as a “root user”.

sudo su -
Root Access Command
Root Access Command

Step 15: To check the version of the docker, type the “docker –version” command.

docker--version
Check the docker version
Check the docker version

Step 16: Check the docker status with the “systemctl status docker.io” command.

systemctl status docker.io
Status Command
Status Command
Status Active
Status Active

Docker is in an “Active” State.

Step 17: For pulling the “Ubuntu Image”, use “docker pull Ubuntu”. The docker image will be fetched from the docker directory.

docker pull ubuntu
Pull Ubuntu Image
Pull Ubuntu Image

Step 18: Type the “docker images” command to check the “Ubuntu” image. The “Ubuntu” image will be found.

docker images
docker images
docker images

B. Create a container using Ubuntu, and map port 80 on the local

Step 1: Run this command: “docker run -itd -p 80:80 — name test ubuntu” & it will create & do port mapping of a container.

docker run -itd -p 80:80 - name test ubuntu
Container Created
Container Created

Step 2: Run “docker container ls –a” & you will notice that the “test” container is mapped on port 80 successfully.

docker container ls -a
Container with Port
Container with Port

C. Install apache2 on this container

Step 1: Go inside the “test” container. Use this command: “docker exec –it test bash”.

docker exec -it test bash
Go Inside Container
Go Inside Container

Step 2: First run the “apt update” command to update the machine.

apt update
update the machine again
update the machine again

Step 3: Run the “apt install apache2” command to Install the apache2 web server.

apt install apache2
install apache2
install apache2

Step 4: Use the “service apache2 status” command to check the “Apache2” server status. “Apache2 is not running”.

service apache2 status
Apache is Running or Not
Apache is Running or Not

Step 5: Use this command: “service apache2 start” to start the server.

service apache2 start
Start Apache2 Service
Start Apache2 Service

Apache 2 will start after running this command. You can check the status using the “service apache2 status” command.

D. Check if you can access the Apache page on your browser

Step 1: Go to the “Instances” pages & click on “open address” in “Public IPv4 address”.

Go to Instance
Go to Instance

Step 2: The Apache web page will be successfully accessed.

Apache2 Web Page
Apache Web Page

More DevOps Resources:

DevOps Capstone Project 1 -Implementing a DevOps Lifecycle on a website using Docker & Jenkins Only

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

Create a Docker File Which Installs Apache2 Automatically After Running the Container — Docker Assignment 4

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

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

--

--