Multi-Stage Dockerfile

Multi-Stage Dockerfile

Helps create efficient, secure multi-stage Dockerfiles with builder and runtime stages, minimal base images, layer caching and non-root users.

Skill files1 file
SKILL.md47 lines
1
---
2
name: multi-stage-dockerfile
3
description: 'Create optimized multi-stage Dockerfiles for any language or framework'
4
---
5
6
Your goal is to help me create efficient multi-stage Dockerfiles that follow best practices, resulting in smaller, more secure container images.
7
8
## Multi-Stage Structure
9
10
- Use a builder stage for compilation, dependency installation, and other build-time operations
11
- Use a separate runtime stage that only includes what's needed to run the application
12
- Copy only the necessary artifacts from the builder stage to the runtime stage
13
- Use meaningful stage names with the `AS` keyword (e.g., `FROM node:18 AS builder`)
14
- Place stages in logical order: dependencies → build → test → runtime
15
16
## Base Images
17
18
- Start with official, minimal base images when possible
19
- Specify exact version tags to ensure reproducible builds (e.g., `python:3.11-slim` not just `python`)
20
- Consider distroless images for runtime stages where appropriate
21
- Use Alpine-based images for smaller footprints when compatible with your application
22
- Ensure the runtime image has the minimal necessary dependencies
23
24
## Layer Optimization
25
26
- Organize commands to maximize layer caching
27
- Place commands that change frequently (like code changes) after commands that change less frequently (like dependency installation)
28
- Use `.dockerignore` to prevent unnecessary files from being included in the build context
29
- Combine related RUN commands with `&&` to reduce layer count
30
- Consider using COPY --chown to set permissions in one step
31
32
## Security Practices
33
34
- Avoid running containers as root - use `USER` instruction to specify a non-root user
35
- Remove build tools and unnecessary packages from the final image
36
- Scan the final image for vulnerabilities
37
- Set restrictive file permissions
38
- Use multi-stage builds to avoid including build secrets in the final image
39
40
## Performance Considerations
41
42
- Use build arguments for configuration that might change between environments
43
- Leverage build cache efficiently by ordering layers from least to most frequently changing
44
- Consider parallelization in build steps when possible
45
- Set appropriate environment variables like NODE_ENV=production to optimize runtime behavior
46
- Use appropriate healthchecks for the application type with the HEALTHCHECK instruction
47

© GitHub, Inc. · MIT · source · posted by @OpenSourceBuffGuy on promptparty.com

@OpenSourceBuffGuy

I find openly licensed prompts and post them here.

0 followers · 14,621 prompts

More by @OpenSourceBuffGuy

See all
Sea turtle carrying floating film studio island prompt image

Sea turtle carrying floating film studio island

Draws a giant sea turtle carrying a floating island film studio through a starry sky, where fairies polish rough film strips into golden film.

image-prompt, nano-banana, 3d-render, cartoon, fantasy-world, creatures, animals, whimsical, dreamy, cinematic, dramatic-lighting, vibrant-colors, bokeh, miniature, widescreen, night-scene, illustration, concept-art, surreal, storytelling, clay-3d

Desert buggy escapes drones past industrial outpost prompt image

Desert buggy escapes drones past industrial outpost

Builds a 15-second desert chase video where a racer in an armored buggy escapes drones past an industrial outpost, using five reference images with set jobs.

video-prompt, hailuo, action, multi-shot, timed-beats, camera-movement, reference-image, character-consistency, negative-prompt, cinematic, sci-fi, cars, landscape, aerial-view, tracking-shot, photorealistic, sound-effects, structured-output, long-form, widescreen

1 view
Cozy Pixel Art Farm Island Village prompt image

Cozy Pixel Art Farm Island Village

Draws a cozy 16-bit pixel-art farming village across six small islands joined by bridges, with exact counts for buildings, animals and crops.

image-prompt, gpt-image, pixel-art, isometric, game-assets, concept-art, maps, worldbuilding, cozy, vibrant-colors, ocean, landscape, wide-shot, widescreen, game-development, video-games, structured-output, whimsical, summer, high-angle, aerial-view, animals, negative-prompt, cityscape

1 view

Reviews

Loading reviews…

Discussion

Loading comments…