Getting Started with Docker: A Practical Guide
Learn Docker fundamentals — install Docker, understand images and containers, run your first container, and write a basic Dockerfile for your own application.
Getting Started with Docker: A Practical Guide
Docker makes it easy to package applications and their dependencies into containers that run anywhere. This guide covers everything you need to get started.
Prerequisites
- A Linux server or Windows/Mac with Docker Desktop
- Basic terminal knowledge
Step 1: Install Docker
On Ubuntu/Debian:
curl -fsSL https://get.docker.com -o get-docker.sh
sudo sh get-docker.sh
sudo usermod -aG docker $USERLog out and back in for the group change to take effect.
Verify installation:
docker --version
docker run hello-worldStep 2: Understand Key Concepts
- Image — A read-only template with your application and dependencies
- Container — A running instance of an image
- Dockerfile — Instructions to build an image
- Volume — Persistent storage for containers
- Network — Communication between containers
Step 3: Run Your First Container
# Run an Nginx web server
docker run -d -p 8080:80 --name my-web nginxCheck running containers
docker psView logs
docker logs my-webStop the container
docker stop my-webVisit http://localhost:8080 to see the Nginx welcome page.
Step 4: Write a Dockerfile
Create a simple Node.js application:
mkdir my-app && cd my-appCreate app.js:
const http = require('http');
const server = http.createServer((req, res) => {
res.writeHead(200, { 'Content-Type': 'text/plain' });
res.end('Hello from Docker!');
});
server.listen(3000, () => console.log('Server running on port 3000'));Create Dockerfile:
FROM node:20-alpine
WORKDIR /app
COPY app.js .
EXPOSE 3000
CMD ["node", "app.js"]Build and run:
docker build -t my-app .
docker run -d -p 3000:3000 my-appStep 5: Docker Compose
Create docker-compose.yml for multi-container apps:
version: '3.8'
services:
web:
build: .
ports:
- "3000:3000"
db:
image: postgres:16
environment:
POSTGRES_PASSWORD: secret
volumes:
- pgdata:/var/lib/postgresql/datavolumes:
pgdata:
docker compose up -d
docker compose logs
docker compose downEssential Commands Cheat Sheet
docker ps— List running containersdocker ps -a— List all containersdocker images— List imagesdocker exec -it— Shell into a containerbash docker rm— Remove a containerdocker rmi— Remove an imagedocker system prune— Clean up unused resources
Conclusion
You now understand Docker fundamentals and can build, run, and manage containers. Next steps: explore Docker networking, multi-stage builds, and container orchestration with Kubernetes.