# Storage and cleanup

Where your registry's bytes are, what counts toward your quota and your bill, and when deleted images stop costing.

Image layers are content-addressed and stored once per organization: a layer that ten
repositories use is stored, quota-counted and billed once. Deleting a tag, an image or a
repository removes what points at the layers; the layers themselves go later, in layer cleanup.

## The three parts of what is stored

Every stored layer is in exactly one of three parts, so they add up to the total:

| Part                      | What it is                                                                         | Quota | Bill |
| ------------------------- | ---------------------------------------------------------------------------------- | ----- | ---- |
| **In repositories**       | Layers of images you have, and uploads of the last hour (a push in progress)       | yes   | yes  |
| **Waiting to be purged**  | Layers only images a lifecycle rule deleted hold; restorable until they are purged | no    | yes  |
| **Not used by any image** | Left over from deleted tags, images and repositories                               | no    | no   |

## Layer cleanup

Layer cleanup runs every hour at minute 17 (UTC). A layer that no repository of your organization
holds, and that nothing has referenced for 24 hours, is deleted; the 24 hours protect a push still
in flight. An upload not finished within 24 hours of its start is discarded the same way. Each run that frees anything
records one event for your registry: "Garbage collection deleted N unreferenced layers (size) no
image used any more".

Deutsche Cloud can run layer cleanup in report-only mode. Then nothing is deleted, the third part
grows, and your total is larger than your repositories; those layers still count toward neither
your quota nor your bill. The **Storage** page and `cleanup.mode` (`delete` or `report`) say which
mode applies.

## See it

**Console**
1. Open **Container registry**, then choose **Storage**.

**Where the bytes are** lists **Stored in total**, the three parts and **Layer cleanup** (with
the last and the next run). **Repositories** lists each repository's size; **Shared** is the part of
it other repositories hold too, so the sizes can add up to more than **In repositories**.

**CLI**
```sh
dcloud ecr storage get
```

**API**
```http
GET /ecr/api/storage
```

The answer's `breakdown` holds the three parts and `nextPurgeAt`; `quotaUsedBytes` is what the
quota counts.

This needs `ecr:GetRegistryStorage`; without it the console page shows a refusal.

## Related

- [Set a storage quota](set-a-storage-quota.md)
- [Lifecycle policies](lifecycle-policies.md)
