Docker Full Tutorial — Part 2: Installation & First Containers

By Suraj Ahir November 05, 2025 6 min read

Docker — Docker Images
Docker — Docker Images
← Part 1 Docker Tutorial · Part 2 of 12 Part 3 →

In Part 1 we understood why Docker exists and what problem it solves. Now we get hands-on. We will install Docker, understand its architecture, and run our first real containers. By the end of this part, you will have a working Docker setup and understand what actually happens when you type docker run.

Installing Docker on Ubuntu/Debian

This is the most common setup for developers and cloud servers. Follow these steps carefully:

Docker Install — Ubuntu
# Remove old versions first
sudo apt remove docker docker-engine docker.io containerd runc

# Update and install dependencies
sudo apt update
sudo apt install ca-certificates curl gnupg lsb-release

# Add Docker's official GPG key
sudo mkdir -p /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg

# Add Docker repository
echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null

# Install Docker Engine
sudo apt update
sudo apt install docker-ce docker-ce-cli containerd.io docker-compose-plugin

# Start Docker and enable on boot
sudo systemctl start docker
sudo systemctl enable docker

# Run Docker without sudo (important!)
sudo usermod -aG docker $USER
newgrp docker

Installing Docker on Windows

Download Docker Desktop from the official Docker website. Docker Desktop for Windows includes everything you need: Docker Engine, Docker CLI, Docker Compose, and a visual dashboard. It requires Windows 10 or 11 with WSL2 (Windows Subsystem for Linux) enabled. During installation, Docker will ask you to install WSL2 if it is not already set up — follow the prompts and it will guide you through.

After installation, Docker Desktop runs in the system tray. You can interact with Docker via PowerShell or Command Prompt using the same commands you would use on Linux.

Installing Docker on Mac

Download Docker Desktop for Mac from the official Docker website. There are two versions — one for Intel chips and one for Apple Silicon (M1, M2, M3). Make sure you download the right one for your machine. After installation, Docker Desktop gives you a menu bar icon and a dashboard to manage containers visually.

Verifying Docker Installation

After installing, verify that Docker is working correctly:

Verify Docker
docker --version
docker info

If you see version information, Docker is installed. Now run the classic test container:

Hello World Container
docker run hello-world

This command pulls a tiny test image from Docker Hub and runs it. You will see a message confirming that Docker is working correctly. Let us understand exactly what happened here:

Essential Docker Commands You Must Know

These are the commands you will use constantly. Do not just read them — run each one and observe the output.

Core Docker Commands
# Pull an image from Docker Hub
docker pull ubuntu

# List downloaded images
docker images

# Run a container (interactive mode)
docker run -it ubuntu bash

# List running containers
docker ps

# List all containers (including stopped)
docker ps -a

# Stop a running container
docker stop <container_id>

# Remove a container
docker rm <container_id>

# Remove an image
docker rmi ubuntu

Running Your First Real Container

Let us run something more meaningful — an Nginx web server inside a container:

Run Nginx Container
docker run -d -p 8080:80 --name my-web nginx

Breaking down this command:

Open your browser and go to http://localhost:8080. You will see the Nginx welcome page. A full web server running inside a container — no installation required on your host machine.

Understanding Container Lifecycle

A Docker container goes through specific states: created, running, stopped, and removed. Understanding this lifecycle is important because containers are meant to be disposable. You can stop them, delete them, and create new ones from the same image in seconds. The image stays — only the container instance is deleted when you run docker rm.

This is fundamentally different from a virtual machine. A VM takes minutes to start. A container takes milliseconds. A VM has its own full OS. A container shares the host OS kernel. This is why containers are so powerful for modern development and deployment workflows.

Viewing Container Logs

When a container runs in the background, how do you know what it is doing? Docker captures all output from the container process and stores it as logs.

Container Logs
# View logs of a container
docker logs my-web

# Follow logs in real time
docker logs -f my-web

This is your window into what is happening inside a running container. In production systems, log monitoring is critical — Docker's logging system makes it straightforward.

Entering a Running Container

Sometimes you need to get inside a container and look around or troubleshoot. Use this command:

Enter Running Container
docker exec -it my-web bash

This opens a bash shell inside the running Nginx container. You can browse the filesystem, check configuration files, and run commands just as you would on a regular Linux server. Type exit to leave the container without stopping it.

Cleanup — Good Practice

Containers and images accumulate quickly and take up disk space. Keep your Docker environment clean:

Docker Cleanup
# Remove all stopped containers
docker container prune

# Remove unused images
docker image prune

# Remove everything unused (containers, networks, images)
docker system prune

In Part 3, we will learn to write our own Dockerfile and build custom images — this is where Docker becomes truly powerful for real projects.

Disclaimer: This content is for educational purposes only. SRJahir Tech does not guarantee any specific outcome or job placement.