DevOps-Containerization

Docker Experiment 2 — Installation, Configuration & Container Lifecycle

Overview

This experiment demonstrates the practical implementation of containerization using Docker. The goal is to understand how Docker images are pulled, containers are deployed, services are exposed using port mapping, and how the complete container lifecycle is managed.

Containers provide lightweight, fast, and portable environments compared to traditional virtual machines. This lab focuses on real-world Docker CLI operations used in DevOps and Cloud environments.


Objectives


System Requirements

| Component | Details | |———–|———| | OS | Windows / Linux / macOS | | Software | Docker Desktop | | Network | Active Internet connection | | Interface | Terminal / PowerShell |


Docker Concepts Used

| Concept | Explanation | |———|————-| | Image | Read-only template used to create containers | | Container | Running instance of an image | | Port Mapping | Connects host port to container port | | Detached Mode | Runs container in background | | Docker Hub | Public image repository |


Step-by-Step Procedure

Step 1 — Pull nginx Image

docker pull nginx

Downloads the official nginx web server image.


Step 2 — Run Container with Port Mapping

docker run -d -p 8080:80 nginx

| Option | Meaning | |——–|———| | -d | Detached mode | | -p 8080:80 | Maps host port 8080 → container port 80 | | nginx | Image name |

Now open: http://localhost:8080


Step 3 — Verify Running Containers

docker ps

Displays container ID, image, status, and port mappings.


🔹 Step 4 — Stop Container

docker stop <container_id>

Step 5 — Remove Container

docker rm <container_id>

Step 6 — Remove Docker Image

docker rmi nginx

Observed Behavior


Results

The nginx image was pulled, container deployed, verified, stopped, removed, and the image deleted successfully.


Conclusion

Docker simplifies application deployment using containers. Compared to VMs, containers start faster, consume fewer resources, and are ideal for cloud-native microservices.


Key Takeaways