Skip to content

Common Mistakes Beginners Make

Terminal window
# Bad: random names like "nervous_darwin"
docker run -d nginx
# Good: meaningful names
docker run -d --name web-server nginx

Terminal window
# Bad: unpredictable updates
docker run node:latest
# Good: pin to specific version
docker run node:18.17.0-alpine3.18

❌ Mistake 3: Storing Data Inside Containers

Section titled “❌ Mistake 3: Storing Data Inside Containers”
Terminal window
# Bad: data lost when container is removed!
docker run -d mongo
# Good: use a volume
docker run -d -v mongo-data:/data/db mongo

Terminal window
# Error: port 8080 already in use
docker run -p 8080:80 nginx
# Fix: check what's using the port
lsof -i :8080 # macOS/Linux
netstat -ano | findstr :8080 # Windows
# Or use a different host port
docker run -p 8081:80 nginx

Terminal window
# Bad: full OS image (~1GB)
FROM ubuntu:22.04
RUN apt-get install nodejs
# Good: use official slim/alpine images (~50MB)
FROM node:18-alpine

Without .dockerignore, your node_modules (often 500MB+) gets copied into the build context.

Terminal window
# Create .dockerignore
cat > .dockerignore << 'EOF'
node_modules
.git
.env
*.log
dist
build
.DS_Store
EOF

Terminal window
# Accumulated stopped containers, images, volumes eat disk space!
# Check disk usage:
docker system df
# Full cleanup (use carefully!):
docker system prune -a --volumes
# Safer: clean specific resources
docker container prune
docker image prune
docker volume prune
docker network prune

❌ Mistake 8: Running as Root Inside Containers

Section titled “❌ Mistake 8: Running as Root Inside Containers”
Terminal window
# Bad: container runs as root by default (security risk)
FROM node:18-alpine
CMD ["node", "app.js"]
# Good: create and use a non-root user
FROM node:18-alpine
RUN addgroup -S appgroup && adduser -S appuser -G appgroup
USER appuser
CMD ["node", "app.js"]