Docker Image Management Skill¶
This skill provides comprehensive guidance and tools for working with Docker containers and images. It covers everything from creating optimized Dockerfiles to managing container lifecycles and troubleshooting common issues.
Files in This Skill¶
SKILL.md- Main skill documentation with detailed instructions and best practicesdockerfile-templates.md- Ready-to-use Dockerfile templates for different languages and frameworksdocker-compose-examples.yml- Sample docker-compose configurations for various application architecturesdockerignore-template- Comprehensive .dockerignore templates for different project typesdocker-manage.sh- Bash script for common Docker operationsREADME.md- This file with overview and quick start guide
Quick Start¶
1. Basic Containerization¶
For a simple Node.js application:
- Copy a Dockerfile template from
dockerfile-templates.md - Create a
.dockerignorefile based ondockerignore-template - Build and run using the management script:
# Make script executable
chmod +x docker-manage.sh
# Build image
./docker-manage.sh build myapp:v1.0
# Run container
./docker-manage.sh run myapp:v1.0 myapp-container 3000:3000
2. Multi-Container Applications¶
For applications requiring multiple services:
- Copy a docker-compose configuration from
docker-compose-examples.yml - Customize environment variables and service configurations
- Run the application:
3. Development Workflow¶
For development environments:
- Use the development docker-compose example
- Mount source code as volumes for hot reloading
- Access debug ports for debugging
Common Use Cases¶
Web Applications¶
- Single-page applications (React, Vue, Angular)
- API servers (Express, Flask, Django)
- Full-stack applications
Microservices¶
- Service mesh configurations
- API gateways
- Database services
Development Environments¶
- Consistent development setup across team
- Isolated dependencies
- Easy onboarding for new developers
CI/CD Pipelines¶
- Automated testing environments
- Build artifacts
- Deployment containers
Best Practices Summary¶
Image Optimization¶
- Use multi-stage builds to reduce image size
- Choose appropriate base images (Alpine for smaller size)
- Clean up caches and temporary files
- Use .dockerignore to exclude unnecessary files
Security¶
- Run containers as non-root users
- Keep base images updated
- Don't store secrets in images
- Scan images for vulnerabilities
Performance¶
- Optimize layer caching order
- Minimize number of layers
- Use buildkit for faster builds
- Consider image size vs build time trade-offs
Troubleshooting¶
Common Issues¶
Container exits immediately: - Check CMD/ENTRYPOINT in Dockerfile - Verify application dependencies are installed - Check for missing environment variables
Port conflicts:
- Use different host ports
- Stop conflicting containers
- Check docker ps for running containers
Permission denied: - Ensure proper user setup in Dockerfile - Check file permissions on host - Avoid running containers as root when possible
Slow builds: - Optimize .dockerignore - Reorder COPY commands for better caching - Use multi-stage builds - Enable BuildKit
Debug Commands¶
# View container logs
docker logs <container_name>
# Execute commands in running container
docker exec -it <container_name> /bin/bash
# Inspect container configuration
docker inspect <container_name>
# Check container resource usage
docker stats <container_name>
Integration with Development Workflow¶
Version Control¶
- Commit Dockerfile and docker-compose.yml
- Consider committing docker-manage.sh for team use
- Use .dockerignore to exclude build artifacts
CI/CD Integration¶
- Use GitHub Actions or other CI systems
- Build images automatically on commits
- Run tests in containers
- Deploy using container orchestration
Team Collaboration¶
- Document container setup in project README
- Share common patterns and templates
- Establish naming conventions for images and containers
Additional Resources¶
- Docker Documentation
- Docker Best Practices Guide
- Docker Compose Documentation
- Docker Security Best Practices
Contributing¶
When contributing to this skill:
- Test all examples and scripts
- Update documentation for new features
- Follow the established patterns and conventions
- Add examples for new use cases
- Validate with the skill validation script from the skill-creator skill