dockerfile-best-practices

Dockerfile Best Practices Reference

Content Preview
# Dockerfile Best Practices Reference

## Layer Optimization

### The Golden Rule
Every `RUN`, `COPY`, and `ADD` instruction creates a new layer. Fewer layers = smaller image.

### Combine Related Commands
```dockerfile
# Bad — 3 layers
RUN apt-get update
RUN apt-get install -y curl git
RUN rm -rf /var/lib/apt/lists/*

# Good — 1 layer
RUN apt-get update && \
    apt-get install -y --no-install-recommends curl git && \
    rm -rf /var/lib/apt/lists/*
```

### Order Layers by Change Frequency
```
How to Use

Recommended: Install to project (local)

mkdir -p .claude/skills
curl -o .claude/skills/dockerfile-best-practices.md \
  https://raw.githubusercontent.com/alirezarezvani/claude-skills/main/engineering/docker-development/references/dockerfile-best-practices.md

Skill is scoped to this project only. Add .claude/skills/ to your .gitignoreif you don't want to commit it.

Alternative: Clone full repo

git clone https://github.com/alirezarezvani/claude-skills

Then reference at engineering/docker-development/references/dockerfile-best-practices.md

Related Skills