Docker Introduction for Developers
Learn Docker basics to containerize your applications.
What Is Docker?
Docker packages your application with all dependencies into a container. Ensures consistent behavior across development, testing, and production environments.
Dockerfile
FROM node:18-alpine
WORKDIR /app
COPY package*.json ./
RUN npm install
COPY . .
EXPOSE 3000
CMD ["npm", "start"]
Essential Commands
# Build the image
docker build -t my-app .
# Run a container
docker run -p 3000:3000 my-app
# List containers
docker ps
# Stop container
docker stop container_id
docker-compose
version: '3.8'
services:
app:
build: .
ports:
- "3000:3000"
db:
image: postgres:15
environment:
POSTGRES_PASSWORD: secret
Conclusion
Docker eliminates "works on my machine" problems forever. Essential for modern development and deployment workflows.