What Are Containers?
Containers package applications with all dependencies, ensuring they run consistently across different environments. Docker makes containerization simple and accessible.
Why Use Docker?
- Consistent development and production environments
- Easy deployment and scaling
- Isolation between applications
- Efficient resource utilization
Installing Docker
Download Docker Desktop from docker.com. Verify installation:
docker --version
docker run hello-world
Your First Container
# Run nginx web server
docker run -d -p 8080:80 nginx
# Visit http://localhost:8080 in browser
Creating a Dockerfile
FROM node:18
WORKDIR /app
COPY package*.json ./
RUN npm install
COPY . .
EXPOSE 3000
CMD ["node", "server.js"]
Essential Docker Commands
# Build image
docker build -t myapp .
# Run container
docker run -d -p 3000:3000 myapp
# List running containers
docker ps
# Stop container
docker stop <container-id>
Next Steps
Learn Docker Compose for multi-container apps, explore Kubernetes for orchestration, and study best practices for production deployments.
