Docker Reference
Docker is a platform for developing, shipping, and running applications in containers. This section provides comprehensive command references for working with Docker.
Quick Navigation
| Section | Description |
|---|---|
| Images | Pull, list, remove, and manage Docker images |
| Containers | Create, run, manage, and debug containers |
| Compose | Multi-container applications with Docker Compose |
Common Workflows
Quick Container Setup
bash
# Pull an image
docker pull ubuntu:latest
# Create and run a container
docker run -it --name myapp ubuntu:latest /bin/bash
# Verify running containers
docker container listDevelopment Workflow
bash
# Start development containers
docker-compose up -d
# View logs
docker-compose logs -f
# Execute commands in running container
docker-compose exec app bash
# Stop containers
docker-compose downCleanup
bash
# Remove stopped containers
docker container prune
# Remove unused images
docker image prune -a
# Clean everything (use with caution)
docker system prune -a --volumesInstallation
Linux
bash
# Install Docker using convenience script
curl -fsSL https://get.docker.com -o get-docker.sh
sudo sh get-docker.sh
# Add user to docker group (to run without sudo)
sudo usermod -aG docker $USER
# Start Docker service
sudo systemctl start docker
sudo systemctl enable dockermacOS
Download and install Docker Desktop for Mac.
Windows
Download and install Docker Desktop for Windows.
Essential Commands
System Information
bash
# Docker version
docker --version
# System information
docker info
# Disk usage
docker system dfQuick Reference
| Task | Command |
|---|---|
| List images | docker image list |
| List containers | docker container list --all |
| View logs | docker logs <container> |
| Execute command | docker exec -it <container> <command> |
| Clean system | docker system prune |
Best Practices
Security
- Don't run containers as root: Use
USERdirective in Dockerfile - Scan images for vulnerabilities: Use
docker scan <image> - Use official images: Pull from verified publishers when possible
- Keep images updated: Regularly update base images
Performance
- Use .dockerignore: Exclude unnecessary files from build context
- Multi-stage builds: Reduce final image size
- Layer caching: Order Dockerfile commands for optimal caching
- Minimize layers: Combine RUN commands where appropriate
Organization
- Tag images properly: Use semantic versioning
- Clean up regularly: Remove unused images and containers
- Use docker-compose: Manage multi-container applications
- Document configurations: Add comments to Dockerfiles and compose files
Troubleshooting
Container Won't Start
bash
# Check logs for errors
docker logs <container>
# Inspect container configuration
docker inspect <container>
# Try running interactively
docker run -it <image> /bin/bashPermission Denied Errors
bash
# Linux: Add user to docker group
sudo usermod -aG docker $USER
# Then log out and log back inOut of Disk Space
bash
# Check disk usage
docker system df
# Clean up
docker system prune -a --volumesSee Also
- Docker Images - Detailed image management
- Docker Containers - Container operations
- Docker Compose - Multi-container orchestration
- .NET Core Commands - Publishing .NET apps to Docker
External Resources
- Docker Documentation
- Docker Hub - Public image registry
- Dockerfile Reference
- Docker Compose Documentation