After understanding Docker fundamentals and Docker Architecture, the next step is installing Docker and running your first container.

In this article, you will learn how to install Docker, verify the installation and execute your first Docker container using practical examples.
Why Install Docker?
Docker allows developers to build, package and run applications consistently across different environments.
Instead of manually installing dependencies on every machine, Docker packages everything into containers.
Application + Dependencies + Runtime = Docker Container
Docker Desktop
Docker Desktop is the easiest way to use Docker on Windows and macOS.
Docker Desktop includes:
- Docker Engine
- Docker CLI
- Docker Compose
- Docker Dashboard
Installing Docker on Windows
- Download Docker Desktop.
- Run the installer.
- Restart the system if required.
- Launch Docker Desktop.
- Wait for Docker Engine to start.
After installation completes, Docker runs as a background service.
Installing Docker on macOS
- Download Docker Desktop for macOS.
- Open the installation package.
- Move Docker to Applications.
- Launch Docker Desktop.
- Allow required permissions.
Installing Docker on Linux
Most Linux distributions support Docker Engine.
sudo apt update sudo apt install docker.io
Start Docker service:
sudo systemctl start docker
Enable Docker at startup:
sudo systemctl enable docker
Verify Docker Installation
After installation, verify Docker using:
docker --version
Example output:
Docker version 28.x.x
If Docker returns the version successfully, installation is complete.
First Docker Command
The easiest command to test Docker is:
docker run hello-world
This command downloads a test image and runs a container.
What Happens Internally?
When you execute:
docker run hello-world
Docker performs the following steps:
Check Image Locally ↓ Image Not Found ↓ Download Image ↓ Create Container ↓ Start Container ↓ Display Output
Hello World Output
A successful execution produces output similar to:
Hello from Docker! This message shows that your installation appears to be working correctly.
This means Docker is functioning correctly.
Downloading an Image
Docker images are stored in registries such as Docker Hub.
Download Nginx:
docker pull nginx
Docker downloads the image to your local machine.
Viewing Downloaded Images
Display available images:
docker images
Example:
REPOSITORY TAG nginx latest hello-world latest
Running a Container
Create and run an Nginx container:
docker run nginx
Docker creates a running container from the Nginx image.
Run a Container in Detached Mode
Containers can run in the background.
docker run -d nginx
The -d option means detached mode.
View Running Containers
docker ps
Example output:
CONTAINER ID IMAGE STATUS PORTS
This displays currently running containers.
View All Containers
docker ps -a
This command shows both active and stopped containers.
Stop a Container
Identify container id:
docker ps
Stop container:
docker stop container-id
Remove a Container
Delete a stopped container:
docker rm container-id
This removes the container entirely.
Container Lifecycle
Image ↓ Container Created ↓ Running ↓ Stopped ↓ Removed
Understanding this lifecycle is important for Docker administration.
Real World Example
Suppose a team develops a Spring Boot REST API.
Without Docker:
Install Java Install Maven Configure Environment Deploy Application
With Docker:
docker run springboot-api
The application runs consistently regardless of the host machine.
Most Useful Beginner Commands
| Command | Purpose |
|---|---|
| docker --version | Check Docker Version |
| docker pull | Download Image |
| docker images | List Images |
| docker run | Create Container |
| docker ps | List Running Containers |
| docker stop | Stop Container |
| docker rm | Delete Container |
Common Interview Questions
How do you verify Docker installation?
Using:
docker --version
What does docker run do?
It creates and starts a container from an image.
What does docker pull do?
It downloads images from a Docker Registry.
What is detached mode?
Detached mode runs containers in the background.
How do you view running containers?
Using:
docker ps
Best Practices
- Use official images whenever possible.
- Remove unused containers regularly.
- Verify image sources before downloading.
- Use specific image versions instead of latest in production.
- Learn basic commands before advanced concepts.
Frequently Asked Questions (FAQ)
Can Docker run without Docker Hub?
Yes. Docker can use private registries.
Can one image create multiple containers?
Yes. Multiple containers can be created from a single image.
Do containers remain after stopping?
Yes. Containers remain unless removed explicitly.
Conclusion
Installing Docker and running your first container is the first practical step toward modern containerized development. Understanding images, containers and basic Docker commands provides the foundation required for Dockerfiles, Docker Compose, Kubernetes and cloud-native application deployment.
Keywords
Docker Installation, Docker Desktop, Docker Run Command, Docker Pull Command, Docker Tutorial, Docker for Beginners, Docker Commands, Run First Docker Container, Docker Images, Docker Containers, Docker Setup, DevOps Tutorial, Containerization, Docker Interview Questions, Spring Boot Docker
Reviewed by 13thGhost
on
12:25 AM
Rating: