Docker – I Assignment - 2
Task
● Save the image created in Assignment 1 as a Docker image
● Launch container from this new image and map the port to 81
● Go inside the container and start the apache2 service
● Check if you are able to access it on the browser
Solution
1. Open a terminal and navigate to the directory where the Dockerfile and HTML
file are located.
2. Build the Docker image using the following command
docker build -t myimage:v1 .
3. Once the image is built, you can confirm it is listed by running the following
command:
docker images
4. Launch a container from the new image and map the port to 81 using the
following command:
docker run -d -p 81:80 myimage:v1
The -d flag runs the container in detached mode and the -p flag maps port 81
on the host machine to port 80 in the container.
5. Inside the container using the following command
docker exec -it docker_assignment_2 /bin/bash
6. Start the Apache2 service by running the following command:
service apache2 start
7. Check if able to access it on the browser by opening a web browser and
navigating to http://localhost:81. If everything is working correctly, you should
see the HTML file that was created in Assignment 1.