Launch a Container Using a New Image & Start Apache 2 Sevice Here — Docker Assignment 2

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

You have been asked to:

● Save the container created in Assignment 1 as a Docker image

● Launch the container from this new image and map the port to 81

● Go inside the container and start the apache2 service

● Check if you can access it on the browser

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

Apache2 Default Page
Apache2 Default Page

Git Hub Repository Link for Docker Assignment 2 for Commands

A. Save the container created in Assignment 1 as a Docker image

Step 1: Run this command to convert the container into the image:

sudo docker commit test assignment2
Convert Container Into Images
Convert Container Into Images

When you run the “docker images” command, you will notice that the “assignment2” image has been successfully created.

B. Launch the container from this new image and map the port to 81

Step 1: Run this command to create a container & map into port number 81.

sudo docker run –itd –p 81:80 –name test1 assignment2
docker container ls -a

A new container will be created & mapped onto port number 81.

Container Created & Mapped
Container Created & Mapped

When you run the “docker container ls –a” command, the test1 container is successfully mapped on port number 81.

C. Go inside the container and start the apache2 service

Step 1: Run this command to go inside the container.

sudo docker exec –it test1 bash
Go Inside Test1
Go Inside Test1

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

apt update  
Update the Container
Update the Container

Step 3: To install “apache2”, use this command: “apt install apache2”.

apt install apache2
Install Apache2
Install Apache2

Step 4: Run this command to check whether “Apache2” is running or not. [service apache2 status]. Apache2 is not running.

service apache2 status  
Apache2 is Not Running
Apache2 is Not Running

Step 5: To start the apache2, use this command: service apache2 start.

service apache2 start
service apache2 status
Start Apache2
Start Apache2

When you run the status using this command: “service apache2 status”. Apache2 will be in “Running State” now.

D. Check if you can access it on the browser

Step 1: Go to the “Instances” section & select your instance. Click on “open address”.

Click IP Address Hyperlink
Click IP Address Hyperlink

Step 2: Your Apache2 Web page will be successfully opened on port 81.

Apache2 Default Page
Apache2 Default Page

Read these Docker Guides:

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

--

--