Docker Hub Toolkit
End-to-end automation for deploying Python project images to Docker Hub with maximum performance and efficiency.
What This Skill Does
- Generates optimized multi-stage Dockerfiles (base → builder → dev → production)
- Builds, tags, and pushes images to Docker Hub
- Creates CI/CD pipelines (GitHub Actions) for automated deployment
- Optimizes image size and build speed with BuildKit caching
- Sets up multi-platform builds (amd64/arm64)
- Generates
.dockerignore and docker-compose.yml
- Scans images for security vulnerabilities
- Debugs failed Docker builds
What This Skill Does NOT Do
- Deploy to Kubernetes/ECS/cloud orchestrators (container runtime only)
- Manage Docker Hub billing or account settings
- Handle non-Python project images
- Create Docker Swarm or cluster configurations
- Manage Docker Hub webhooks or automated test integrations
Before Implementation
Gather context to ensure successful implementation:
| Source |
Gather |
| Codebase |
Python framework (FastAPI/Flask/Django), entry point, dependencies file |
| Conversation |
Docker Hub username, image name, target platforms, version tag |
| Skill References |
Multi-stage patterns, CI/CD templates, security practices from references/ |
| User Guidelines |
Team Docker standards, naming conventions, security requirements |
Ensure all required context is gathered before implementing.
Only ask user for THEIR specific requirements (domain expertise is in this skill).
Required Clarifications
Ask about USER'S context:
- Docker Hub credentials: "What is your Docker Hub username/namespace?"
- Project type: "What Python framework? (FastAPI, Flask, Django, script)"
- Entry point: "What command starts your app? (e.g.,
uvicorn app.main:app)"
- Deployment target: "Local push, or automated CI/CD via GitHub Actions?"
Workflow
Full Deployment Pipeline
1. Generate Dockerfile → Multi-stage optimized build
2. Create .dockerignore → Exclude unnecessary files
3. Build image → With BuildKit caching
4. Tag image → Semantic version + git SHA
5. Security scan → Check for vulnerabilities
6. Push to Docker Hub → Authenticated push
7. Set up CI/CD → GitHub Actions automation (optional)
Stage-by-Stage Execution
Stage 1: Generate Base Configuration
- Detect Python version from
pyproject.toml, setup.py, or .python-version
- Identify dependency file (
requirements.txt, pyproject.toml, Pipfile)
- Generate
.dockerignore from assets/templates/dockerignore.template
- Create multi-stage Dockerfile using patterns from
references/multi-stage-builds.md
Stage 2: Build Dependencies Stage
- Use
--mount=type=cache,target=/root/.cache/pip for pip caching
- Use
--mount=type=bind for dependency files
- Install to
--user for clean multi-stage copy
- Verify dependency resolution succeeds
Stage 3: Development/Test Stage (Optional)
- Copy dependencies from builder
- Copy source code
- Run tests (
pytest) and linting
- Target with
docker build --target dev
Stage 4: Production Build & Push
- Fresh slim base image
- Create non-root user
- Copy only runtime dependencies from builder
- Set proper
CMD/ENTRYPOINT
- Tag with version strategy
- Push to Docker Hub
Available Scripts
| Script |
Purpose |
Usage |
scripts/build-and-push.sh |
Build, tag, and push image |
bash scripts/build-and-push.sh USERNAME APP_NAME VERSION |
scripts/validate-dockerfile.sh |
Lint and validate Dockerfile |
bash scripts/validate-dockerfile.sh [path/to/Dockerfile] |
scripts/setup-multiplatform.sh |
Configure buildx for multi-arch |
bash scripts/setup-multiplatform.sh |
Dependencies
- Docker Engine 20.10+ (BuildKit support)
- Docker CLI with buildx plugin
- Docker Hub account with access token
- Git (for SHA-based tagging)
- Python 3.10+ (for the project being containerized)
Error Handling
| Error |
Recovery |
| Build fails on pip install |
Check requirements.txt syntax, verify package availability |
| Push denied/unauthorized |
Run docker login, verify access token |
| Image too large (>500MB) |
Switch to slim base, verify multi-stage COPY |
| BuildKit not available |
Set DOCKER_BUILDKIT=1 or use docker buildx build |
| Multi-platform fails |
Run scripts/setup-multiplatform.sh |
| Rate limit exceeded |
Wait or use authenticated pulls |
See references/troubleshooting.md for comprehensive error resolution.
Input/Output
- Input: Python project with dependency file (requirements.txt/pyproject.toml)
- Output: Optimized Docker image pushed to Docker Hub at
username/app:tag
Output Checklist
Before delivering, verify:
Reference Files
| File |
When to Read |
references/multi-stage-builds.md |
Dockerfile patterns, stage architecture, anti-patterns |
references/docker-hub-deployment.md |
Push workflow, tagging strategy, Hub settings |
references/ci-cd-github-actions.md |
GitHub Actions pipeline, caching, automation |
references/claude-integration.md |
Claude Code commands, hooks, CLAUDE.md standards |
references/troubleshooting.md |
Build/push errors, size issues, security fixes |
documentation/docker_hub_stages.md |
Original multi-stage build stages reference |
documentation/docker_hub_python_project_partner.md |
Claude capabilities for Docker Hub |
1---2name: docker-hub-toolkit3description: Automate Python project Docker Hub deployments with optimized multi-stage builds, CI/CD pipelines, and security best practices. This skill should be used when users ask to containerize Python apps, build Docker images, push to Docker Hub, set up CI/CD for Docker, optimize Dockerfiles, debug Docker build failures, or deploy Python projects as containers.4---5
6# Docker Hub Toolkit
7
8End-to-end automation for deploying Python project images to Docker Hub with maximum performance and efficiency.
9
10## What This Skill Does
11
12- Generates optimized multi-stage Dockerfiles (base → builder → dev → production)
13- Builds, tags, and pushes images to Docker Hub
14- Creates CI/CD pipelines (GitHub Actions) for automated deployment
15- Optimizes image size and build speed with BuildKit caching
16- Sets up multi-platform builds (amd64/arm64)
17- Generates `.dockerignore` and `docker-compose.yml`
18- Scans images for security vulnerabilities
19- Debugs failed Docker builds
20
21## What This Skill Does NOT Do
22
23- Deploy to Kubernetes/ECS/cloud orchestrators (container runtime only)
24- Manage Docker Hub billing or account settings
25- Handle non-Python project images
26- Create Docker Swarm or cluster configurations
27- Manage Docker Hub webhooks or automated test integrations
28
29---
30
31## Before Implementation
32
33Gather context to ensure successful implementation:
34
35| Source | Gather |
36|--------|--------|
37| **Codebase** | Python framework (FastAPI/Flask/Django), entry point, dependencies file |
38| **Conversation** | Docker Hub username, image name, target platforms, version tag |
39| **Skill References** | Multi-stage patterns, CI/CD templates, security practices from `references/` |
40| **User Guidelines** | Team Docker standards, naming conventions, security requirements |
41
42Ensure all required context is gathered before implementing.
43Only ask user for THEIR specific requirements (domain expertise is in this skill).
44
45---
46
47## Required Clarifications
48
49Ask about USER'S context:
50
511. **Docker Hub credentials**: "What is your Docker Hub username/namespace?"
522. **Project type**: "What Python framework? (FastAPI, Flask, Django, script)"
533. **Entry point**: "What command starts your app? (e.g., `uvicorn app.main:app`)"
544. **Deployment target**: "Local push, or automated CI/CD via GitHub Actions?"
55
56---
57
58## Workflow
59
60### Full Deployment Pipeline
61
62```
631. Generate Dockerfile → Multi-stage optimized build
642. Create .dockerignore → Exclude unnecessary files
653. Build image → With BuildKit caching
664. Tag image → Semantic version + git SHA
675. Security scan → Check for vulnerabilities
686. Push to Docker Hub → Authenticated push
697. Set up CI/CD → GitHub Actions automation (optional)
70```
71
72### Stage-by-Stage Execution
73
74#### Stage 1: Generate Base Configuration
75
761. Detect Python version from `pyproject.toml`, `setup.py`, or `.python-version`
772. Identify dependency file (`requirements.txt`, `pyproject.toml`, `Pipfile`)
783. Generate `.dockerignore` from `assets/templates/dockerignore.template`
794. Create multi-stage Dockerfile using patterns from `references/multi-stage-builds.md`
80
81#### Stage 2: Build Dependencies Stage
82
831. Use `--mount=type=cache,target=/root/.cache/pip` for pip caching
842. Use `--mount=type=bind` for dependency files
853. Install to `--user` for clean multi-stage copy
864. Verify dependency resolution succeeds
87
88#### Stage 3: Development/Test Stage (Optional)
89
901. Copy dependencies from builder
912. Copy source code
923. Run tests (`pytest`) and linting
934. Target with `docker build --target dev`
94
95#### Stage 4: Production Build & Push
96
971. Fresh slim base image
982. Create non-root user
993. Copy only runtime dependencies from builder
1004. Set proper `CMD`/`ENTRYPOINT`
1015. Tag with version strategy
1026. Push to Docker Hub
103
104---
105
106## Available Scripts
107
108| Script | Purpose | Usage |
109|--------|---------|-------|
110| `scripts/build-and-push.sh` | Build, tag, and push image | `bash scripts/build-and-push.sh USERNAME APP_NAME VERSION` |
111| `scripts/validate-dockerfile.sh` | Lint and validate Dockerfile | `bash scripts/validate-dockerfile.sh [path/to/Dockerfile]` |
112| `scripts/setup-multiplatform.sh` | Configure buildx for multi-arch | `bash scripts/setup-multiplatform.sh` |
113
114---
115
116## Dependencies
117
118- Docker Engine 20.10+ (BuildKit support)
119- Docker CLI with buildx plugin
120- Docker Hub account with access token
121- Git (for SHA-based tagging)
122- Python 3.10+ (for the project being containerized)
123
124---
125
126## Error Handling
127
128| Error | Recovery |
129|-------|----------|
130| Build fails on pip install | Check requirements.txt syntax, verify package availability |
131| Push denied/unauthorized | Run `docker login`, verify access token |
132| Image too large (>500MB) | Switch to slim base, verify multi-stage COPY |
133| BuildKit not available | Set `DOCKER_BUILDKIT=1` or use `docker buildx build` |
134| Multi-platform fails | Run `scripts/setup-multiplatform.sh` |
135| Rate limit exceeded | Wait or use authenticated pulls |
136
137See `references/troubleshooting.md` for comprehensive error resolution.
138
139---
140
141## Input/Output
142
143- **Input**: Python project with dependency file (requirements.txt/pyproject.toml)
144- **Output**: Optimized Docker image pushed to Docker Hub at `username/app:tag`
145
146---
147
148## Output Checklist
149
150Before delivering, verify:
151
152- [ ] Multi-stage Dockerfile with base → builder → production stages
153- [ ] `.dockerignore` excludes `.git`, `__pycache__`, `.venv`, `.env`, `node_modules`
154- [ ] BuildKit cache mounts used for pip installs
155- [ ] Non-root user in production stage
156- [ ] `PYTHONDONTWRITEBYTECODE=1` and `PYTHONUNBUFFERED=1` set
157- [ ] Image tagged with semantic version
158- [ ] Image pushed successfully to Docker Hub
159- [ ] Image size < 200MB (for typical Python apps)
160- [ ] No secrets or credentials in image layers
161- [ ] CI/CD pipeline configured (if requested)
162
163---
164
165## Reference Files
166
167| File | When to Read |
168|------|--------------|
169| `references/multi-stage-builds.md` | Dockerfile patterns, stage architecture, anti-patterns |
170| `references/docker-hub-deployment.md` | Push workflow, tagging strategy, Hub settings |
171| `references/ci-cd-github-actions.md` | GitHub Actions pipeline, caching, automation |
172| `references/claude-integration.md` | Claude Code commands, hooks, CLAUDE.md standards |
173| `references/troubleshooting.md` | Build/push errors, size issues, security fixes |
174| `documentation/docker_hub_stages.md` | Original multi-stage build stages reference |
175| `documentation/docker_hub_python_project_partner.md` | Claude capabilities for Docker Hub |