analyze-docker-image-size
Scans PHP Docker images to identify size bloat and recommends optimizations to reduce build footprint.
Install
mkdir -p .claude/skills/analyze-docker-image-size && curl -L -o skill.zip "https://agentskills.codes/api/skills/download/19428" && unzip -o skill.zip -d .claude/skills/analyze-docker-image-size && rm skill.zipInstalls to .claude/skills/analyze-docker-image-size
Activation
This is the description your AI agent reads to decide when to run this skill — the better it matches your request, the more reliably it fires.
Analyzes Docker image size for PHP projects. Identifies bloated layers, unnecessary packages, and provides size reduction strategies.Key capabilities
- →Identify bloated layers in Docker images
- →Optimize PHP Dockerfile configurations
- →Implement multi-stage builds for size reduction
- →Clean up build dependencies and package manager caches
- →Generate .dockerignore files to exclude unnecessary files
How it works
The skill analyzes Dockerfile instructions to detect common bloat sources like retained build dependencies, uncleaned caches, and inclusion of development tools, providing optimized alternatives.
Inputs & outputs
When to use analyze-docker-image-size
- →Reduce Docker image size
- →Identify bloated layers in Docker builds
- →Optimize PHP Dockerfile configurations
- →Clean up unnecessary build packages
About this skill
Docker Image Size Analysis
Analyze Docker images for PHP projects to identify bloat sources and provide size reduction strategies.
Expected Size Ranges
| Base Image | Minimal | Typical | Bloated |
|---|---|---|---|
| php:8.4-fpm-alpine | 30-50 MB | 80-120 MB | 200+ MB |
| php:8.4-fpm (Debian) | 150-200 MB | 250-350 MB | 500+ MB |
| php:8.4-cli-alpine | 25-40 MB | 60-100 MB | 180+ MB |
Common Bloat Sources
1. Build Dependencies Not Cleaned
# BLOATED: Dev packages remain in final image
RUN apk add --no-cache $PHPIZE_DEPS icu-dev libzip-dev \
&& docker-php-ext-install intl zip
# OPTIMIZED: Remove build deps after compilation
RUN apk add --no-cache --virtual .build-deps $PHPIZE_DEPS icu-dev libzip-dev \
&& docker-php-ext-install intl zip \
&& apk del .build-deps \
&& apk add --no-cache icu-libs libzip
2. Vendor with Dev Dependencies
# BLOATED: Includes dev dependencies (+30-80MB)
RUN composer install
# OPTIMIZED: No dev dependencies, optimized autoloader
RUN composer install --no-dev --no-scripts --prefer-dist --optimize-autoloader
3. Full Debian Instead of Alpine
# BLOATED: Full Debian base (~150MB base)
FROM php:8.4-fpm
# OPTIMIZED: Alpine base (~30MB base)
FROM php:8.4-fpm-alpine
4. Package Manager Cache
# BLOATED: apt cache retained (~30-50MB)
RUN apt-get update && apt-get install -y libicu-dev
# OPTIMIZED: Clean apt cache in same layer
RUN apt-get update && apt-get install -y --no-install-recommends libicu-dev \
&& rm -rf /var/lib/apt/lists/*
5. Missing .dockerignore
.git
node_modules
vendor
tests
docs
var/cache
var/log
docker-compose*.yml
.env.local
*.md
Makefile
Size Estimation by Component
| Component | Typical Size | Notes |
|---|---|---|
| Alpine base | 5-8 MB | Minimal Linux |
| Debian slim base | 70-90 MB | More packages available |
| PHP runtime | 25-40 MB | Core PHP binaries |
| PHP extensions (5-8) | 10-30 MB | Depends on extensions |
| Composer vendor (no-dev) | 20-60 MB | Depends on packages |
| Composer vendor (with-dev) | 50-150 MB | PHPUnit, etc. |
| Application code | 1-10 MB | Source files only |
| Build dependencies | 50-200 MB | Must be cleaned |
Multi-Stage Build (Best Practice)
FROM php:8.4-fpm-alpine AS builder
RUN apk add --no-cache --virtual .build-deps $PHPIZE_DEPS icu-dev libzip-dev \
&& docker-php-ext-install intl zip opcache \
&& apk del .build-deps
COPY composer.json composer.lock ./
RUN composer install --no-dev --prefer-dist --optimize-autoloader
FROM php:8.4-fpm-alpine AS runtime
RUN apk add --no-cache icu-libs libzip
COPY --from=builder /usr/local/lib/php/extensions/ /usr/local/lib/php/extensions/
COPY --from=builder /usr/local/etc/php/conf.d/ /usr/local/etc/php/conf.d/
COPY --from=builder /var/www/vendor /var/www/vendor
COPY . /var/www/
Grep Patterns
# Find base images used
Grep: "^FROM " --glob "**/Dockerfile*"
# Find missing cache cleanup
Grep: "apt-get install" --glob "**/Dockerfile*"
Grep: "apk add(?!.*--no-cache)" --glob "**/Dockerfile*"
# Find composer install without --no-dev
Grep: "composer install(?!.*--no-dev)" --glob "**/Dockerfile*"
# Find COPY . (copies everything)
Grep: "^COPY \. " --glob "**/Dockerfile*"
# Check for .dockerignore
Glob: "**/.dockerignore"
# Find multi-stage builds
Grep: "^FROM.*AS " --glob "**/Dockerfile*"
Reduction Impact
| Strategy | Size Reduction | Effort |
|---|---|---|
| Alpine instead of Debian | 100-150 MB | Low |
| Multi-stage build | 50-200 MB | Medium |
| Remove build deps | 50-200 MB | Low |
| --no-dev Composer | 30-80 MB | Low |
| Clean apt/apk cache | 20-50 MB | Low |
| .dockerignore | 10-500 MB | Low |
Severity Classification
| Pattern | Severity | Typical Waste |
|---|---|---|
| No multi-stage, build deps remain | Critical | 100-300 MB |
| No .dockerignore, .git copied | Critical | 50-500 MB |
| Debian instead of Alpine (no reason) | Major | 100-150 MB |
| Composer with dev dependencies | Major | 30-80 MB |
| APT/APK cache not cleaned | Minor | 20-50 MB |
Output Format
### Image Size Issue: [Category]
**Severity:** Critical/Major/Minor
**Current Size:** X MB
**Estimated Savings:** Y MB
**Layer:** Dockerfile:line
**Issue:**
[Description of the bloat source]
**Current:**
```dockerfile
// Current Dockerfile instruction
Optimized:
// Optimized Dockerfile instruction
Expected Size After Fix: Before: X MB -> After: Z MB (saved Y MB)
When not to use it
- →Retaining build-time dependencies in production images
- →Copying entire project directories without .dockerignore
- →Using full Debian images when Alpine is sufficient
Limitations
- →Requires manual application of suggested Dockerfile changes
- →Size savings depend on specific project dependencies
How it compares
It provides specific PHP-centric optimization patterns, such as composer --no-dev flags and multi-stage build templates, rather than general container advice.
Compared to similar skills
analyze-docker-image-size side by side with the closest alternatives in the catalog.
| Skill | Installs | Updated | Safety | Difficulty |
|---|---|---|---|---|
| analyze-docker-image-size (this skill) | 0 | 5mo | Review | Intermediate |
| staticphp-build-troubleshooting | 0 | 21d | Review | Intermediate |
| docker-expert | 11 | 6mo | Review | Intermediate |
| deployment-engineer | 4 | 3mo | No flags | Advanced |
Try saying
Example prompts that trigger this skill in your AI assistant.
More by dykyi-roman
View all by dykyi-roman →You might also like
staticphp-build-troubleshooting
crazywhalecc
Diagnose StaticPHP v3 failures. Use when investigating build, compile, linker, download, doctor, environment, CI, smoke-test, terminal output, spc.output.log, spc.shell.log, config.log, CMake logs, or user-provided error snippets from StaticPHP commands.
docker-expert
davila7
Docker containerization expert with deep knowledge of multi-stage builds, image optimization, container security, Docker Compose orchestration, and production deployment patterns. Use PROACTIVELY for Dockerfile optimization, container issues, image size problems, security hardening, networking, and orchestration challenges.
deployment-engineer
sickn33
Expert deployment engineer specializing in modern CI/CD pipelines, GitOps workflows, and advanced deployment automation. Masters GitHub Actions, ArgoCD/Flux, progressive delivery, container security, and platform engineering. Handles zero-downtime deployments, security scanning, and developer experience optimization. Use PROACTIVELY for CI/CD design, GitOps implementation, or deployment automation.
devops
mrgoonie
Deploy to Cloudflare (Workers, R2, D1), Docker, GCP (Cloud Run, GKE), Kubernetes (kubectl, Helm). Use for serverless, containers, CI/CD, GitOps, security audit.
ecs
itsmostafa
AWS ECS container orchestration for running Docker containers. Use when deploying containerized applications, configuring task definitions, setting up services, managing clusters, or troubleshooting container issues.
add-install-docker-ci-e2e
RLinf
Adds install command in install script, Docker build stage in Dockerfile, and CI jobs for docker build, install script, and embodied e2e test when introducing a new model or environment in RLinf. Use when adding a new embodied model (e.g. dexbotic), new env (e.g. maniskill_libero), or new model+env combination that should be installable, dockerized, and tested in CI.