# DOCKER-BP-009: Avoid dnf update

> **Severity:** MEDIUM | **CWE:** CWE-710

- **Language:** Docker
- **Category:** Best Practice
- **URL:** https://codepathfinder.dev/registry/docker/best-practice/DOCKER-BP-009
- **Detection:** `pathfinder scan --ruleset docker/DOCKER-BP-009 --project .`

## Description

Detects use of 'dnf update' in Dockerfiles. Running system updates in Docker builds
creates unpredictable, non-reproducible images and can introduce breaking changes or
security vulnerabilities.

## Vulnerable Code

```python
FROM fedora:latest
RUN dnf update -y  # Bad: Unpredictable, non-reproducible builds
RUN dnf install -y nginx
```

## Secure Code

```python
FROM fedora:38  # Specific version
RUN dnf install -y nginx-1.24.0-1.fc38
# Or install latest from specific base image
RUN dnf install -y nginx
```

## Detection Rule (Python SDK)

```python
from rules.container_decorators import dockerfile_rule
from rules.container_matchers import instruction


@dockerfile_rule(
    id="DOCKER-BP-009",
    name="Avoid dnf update",
    severity="MEDIUM",
    cwe="CWE-710",
    category="best-practice",
    tags="docker,dockerfile,dnf,package-manager,fedora,rhel,update,reproducibility,best-practice,anti-pattern",
    message="Avoid 'dnf update' in Dockerfiles. Use specific base image versions for reproducible builds."
)
def avoid_dnf_update():
    return instruction(type="RUN", contains="dnf update")
```

## How to Fix

- Review your Dockerfile to address the avoid dnf update issue
- Follow Docker official best practices for image building
- Use docker build --check to validate Dockerfile syntax and best practices

## FAQ

**Q: Why does this rule flag avoid dnf update?**

Avoid 'dnf update' in Dockerfiles. Use specific base image versions for reproducible builds.

**Q: How do I fix this?**

Review the secure code example in the playground above and apply the recommended pattern to your Dockerfile or docker-compose.yml.

## References

- [Docker Best Practices](https://docs.docker.com/develop/develop-images/dockerfile_best-practices/)
- [Dockerfile Best Practice: Avoid dnf update](https://docs.docker.com/develop/develop-images/dockerfile_best-practices/#run)

---

Source: https://codepathfinder.dev/registry/docker/best-practice/DOCKER-BP-009
Code Pathfinder — Open source, type-aware SAST with cross-file dataflow analysis
