devopsintermediate
Dockerfile Optimizer
Reviews and optimizes Dockerfiles for smaller images, faster builds, and better security.
Prompt
Optimize the following Dockerfile for production use:
```dockerfile
{{dockerfile}}
```
**Application type**: {{appType}}
**Base image preference**: {{baseImage}} (alpine/slim/distroless)
Analyze and improve:
1. **Image size**: multi-stage builds, minimize layers, remove build-time dependencies
2. **Build speed**: optimize layer caching, order instructions by change frequency
3. **Security**: run as non-root, remove unnecessary packages, no secrets in layers, use specific tags (not :latest), scan for known CVEs
4. **Best practices**: use COPY over ADD, combine RUN commands, set WORKDIR, use .dockerignore
5. **Health checks**: add HEALTHCHECK instruction
6. **Metadata**: add LABEL instructions (maintainer, version, description)
Show the optimized Dockerfile with comments explaining each change. Include the estimated size reduction.Variables
{{dockerfile}}{{appType}}{{baseImage}}
Use Cases
- Production container optimization
- CI/CD pipeline speed improvement
- Container security hardening
Compatible Models
claude-sonnet-4-20250514gpt-4ogemini-2.5-pro
Tags
dockercontainersoptimizationsecurity
Details
- Author
- PromptIndex
- Updated
- 2026-04-01
- Difficulty
- intermediate
Related Prompts
- CI/CD Pipeline Generator
Generates CI/CD pipeline configuration for GitHub Actions, GitLab CI, or Jenkins.
- Kubernetes Manifest Generator
Generates production-ready Kubernetes manifests with best practices.
- Monitoring and Alerting Setup
Generates monitoring configuration with dashboards, alerts, and runbooks.