AIOpenLibraryAIOpenLibrary
Back to Software Engineering

Docker & Container Optimization

Optimize Dockerfiles and container configurations for smaller images, faster builds, and better security.

Updated Mar 11, 2026

ShareLinkedIn

Customize Your Prompt

0/5 filled

Prompt

You are a DevOps engineer specializing in container optimization. Review and optimize my Docker setup.

Current Dockerfile:
```
[DOCKERFILE]
```

Application type: [APP_TYPE]
Base image: [BASE_IMAGE]
Build time: [CURRENT_BUILD_TIME]
Image size: [CURRENT_IMAGE_SIZE]

Optimize for:

1. **Image Size Reduction**:
   - Multi-stage build implementation
   - Base image alternatives (Alpine, distroless, scratch)
   - Layer optimization (ordering, combining RUN commands)
   - .dockerignore improvements

2. **Build Speed**:
   - Layer caching strategy
   - BuildKit features to enable
   - Dependency caching patterns

3. **Security Hardening**:
   - Non-root user
   - Read-only filesystem
   - No unnecessary packages
   - Image scanning recommendations
   - Secret handling (BuildKit secrets, not ENV)

4. **Runtime Performance**:
   - Resource limits (CPU, memory)
   - Health check configuration
   - Graceful shutdown handling

5. **Optimized Dockerfile**: Complete rewritten Dockerfile with comments
6. **docker-compose.yml**: Production-ready compose configuration
7. **Estimated Improvements**: Image size, build time, security score

Powered by Hugging Face Inference API

Pro Tips

  • Most Dockerfiles are unoptimized, leading to 1GB+ images and slow builds. Systematic optimization typically reduces images by 60-80%.

References

Comments

Log in to leave a comment

More Software Engineering Prompts

💻Software Engineering

Senior Developer Code Review

Get a thorough code review from an experienced senior developer perspective, covering correctness, performance, security, and maintainability.

You are a senior software engineer with 15+ years of experience conducting a tho...

Claude Opus 4
IntermediateView prompt
💻Software Engineering

System Architecture Designer

Design scalable system architectures with detailed component diagrams, trade-off analysis, and implementation roadmaps.

You are a principal systems architect. Design a comprehensive system architectur...

Claude Opus 4
AdvancedView prompt
💻Software Engineering

Debug Detective

Systematically debug complex issues by analyzing error messages, stack traces, and code behavior with a structured approach.

You are an expert debugging specialist. Help me systematically debug this issue....

Claude Sonnet 4
IntermediateView prompt

You Might Also Like

✍️Writing & Content✦ Premium

Blog Post Architect

Create SEO-optimized, engaging blog posts with structured outlines, compelling hooks, and strategic keyword placement.

You are an expert content strategist and SEO specialist. Create a comprehensive ...

Claude Opus 4
IntermediateView prompt
📚Education✦ Premium

Socratic Method Tutor

Learn any concept through guided questioning that builds deep understanding instead of memorization.

You are a Socratic tutor. Your role is to help me deeply understand a concept th...

Claude Opus 4
BeginnerView prompt
📦Product Management✦ Premium

Product Requirements Document (PRD)

Generate comprehensive PRDs with user stories, acceptance criteria, technical requirements, and success metrics.

You are a senior product manager at a top tech company. Write a comprehensive PR...

Claude Opus 4
IntermediateView prompt