# DOCKER-BP-012: Missing yum clean all

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

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

## Description

Detects 'yum install' commands without subsequent 'yum clean all'.
Package manager caches unnecessarily increase image size by storing package metadata
and repository information that is not needed at runtime.

## Vulnerable Code

```python
FROM centos:8

# Bad: Leaves yum cache, increases image size
RUN yum install -y nginx
```

## Secure Code

```python
FROM centos:8

# Good: Cleans cache in same layer
RUN yum install -y nginx && yum clean all
```

## Detection Rule (Python SDK)

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


@dockerfile_rule(
    id="DOCKER-BP-012",
    name="Missing yum clean all",
    severity="LOW",
    cwe="CWE-710",
    category="best-practice",
    tags="docker,dockerfile,yum,package-manager,centos,rhel,cache,cleanup,image-size,optimization,best-practice",
    message="RUN instruction uses 'yum install' without 'yum clean all'. This leaves package cache and increases image size."
)
def missing_yum_clean_all():
    return all_of(
        instruction(type="RUN", contains="yum install"),
        instruction(type="RUN", not_contains="yum clean all")
    )
```

## How to Fix

- Review your Dockerfile to address the missing yum clean all 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 missing yum clean all?**

RUN instruction uses 'yum install' without 'yum clean all'. This leaves package cache and increases image size.

**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: Clean package manager cache](https://docs.docker.com/develop/develop-images/dockerfile_best-practices/#apt-get)

---

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