agentsclimarketplace

Analyze docker image size

Skill dykyi-roman/awesome-claude-code/skills/analyze-docker-image-size

Analyzes Docker image size for PHP projects. Identifies bloated layers, unnecessary packages, and provides size reduction strategies.From its SKILL.md

Install
npx -y skills add dykyi-roman/awesome-claude-code --skill analyze-docker-image-size

Assembled from the repository path, not quoted from the project. Check it against their README if it does not work.

SKILL.md

4.7 KB, as published. Nobody here has run it

Docker Image Size Analysis

Analyze Docker images for PHP projects to identify bloat sources and provide size reduction strategies.

Expected Size Ranges

Base ImageMinimalTypicalBloated
php:8.4-fpm-alpine30-50 MB80-120 MB200+ MB
php:8.4-fpm (Debian)150-200 MB250-350 MB500+ MB
php:8.4-cli-alpine25-40 MB60-100 MB180+ 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

ComponentTypical SizeNotes
Alpine base5-8 MBMinimal Linux
Debian slim base70-90 MBMore packages available
PHP runtime25-40 MBCore PHP binaries
PHP extensions (5-8)10-30 MBDepends on extensions
Composer vendor (no-dev)20-60 MBDepends on packages
Composer vendor (with-dev)50-150 MBPHPUnit, etc.
Application code1-10 MBSource files only
Build dependencies50-200 MBMust 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

StrategySize ReductionEffort
Alpine instead of Debian100-150 MBLow
Multi-stage build50-200 MBMedium
Remove build deps50-200 MBLow
--no-dev Composer30-80 MBLow
Clean apt/apk cache20-50 MBLow
.dockerignore10-500 MBLow

Severity Classification

PatternSeverityTypical Waste
No multi-stage, build deps remainCritical100-300 MB
No .dockerignore, .git copiedCritical50-500 MB
Debian instead of Alpine (no reason)Major100-150 MB
Composer with dev dependenciesMajor30-80 MB
APT/APK cache not cleanedMinor20-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)

Keep looking

Skills are one crate of 627,801. Ordering is by how many stacks a row turns up in, so the top of any crate is what has actually been picked rather than what has the most stars.