Docker Skill
Best Practices
- Multi-Stage Builds: Use a builder stage to compile, and a runner stage (Alpine/Slim) for the final image to reduce size.
- Caching: Order usage matters. Copy
package.jsonand install deps BEFORE copying source code to leverage layer caching. - User: Don't run as
root. Create a dedicated user in the Dockerfile.
Common Pitfalls
- Secrets: Baking secrets/env vars into the image. Use Env Vars at runtime.
- Latest Tag: Pin versions (
node:18, notnode:latest) to avoid breaking changes.
References
Converted and distributed by TomeVault — claim your Tome and manage your conversions.