How to Use Docker
A beginner‑friendly guide to installing Docker, running containers, and managing images.
Docker is a platform that lets you package applications and their dependencies into containers. Containers are lightweight, portable, and consistent across environments, making them ideal for development and deployment. This guide covers installing Docker, running your first container, working with images, and basic container management.
Photo by Rubaitul Azad on Unsplash
Step 1: Install Docker
On Linux, install Docker using your package manager:
# Ubuntu / Debian
sudo apt update
sudo apt install docker.io
# Verify installation
docker --version
On macOS and Windows, download Docker Desktop from Docker’s official site.
Step 2: Run Your First Container
Test Docker by running the hello‑world image:
docker run hello-world
This pulls the image from Docker Hub and runs it in a container.
Step 3: Work with Images
Search and pull images from Docker Hub:
docker search nginx
docker pull nginx
Then run the image:
docker run -d -p 8080:80 nginx
This starts Nginx in a container, mapping port 8080 on your machine to port 80 inside the container.
Step 4: Manage Containers
Useful commands for container management:
docker ps # list running containers
docker stop <id> # stop a container
docker rm <id> # remove a container
Replace <id> with the container ID from docker ps.
Step 5: Build Your Own Image
Create a Dockerfile in your project:
# Dockerfile
FROM node:18
WORKDIR /app
COPY package*.json ./
RUN npm install
COPY . .
CMD ["node", "app.js"]
Build and run your image:
docker build -t my-node-app .
docker run -p 3000:3000 my-node-app
Benefits of Docker
- Consistency across development and production environments.
- Lightweight compared to virtual machines.
- Easy to share and deploy applications.
- Huge ecosystem of ready‑made images on Docker Hub.
Conclusion
Docker simplifies application deployment by packaging everything into containers. With installation, image management, and container basics covered, you can start building and running apps in a consistent, portable way.