# Make a repository public

Let anyone pull a repository's images without credentials, or make it private again.

A public repository serves anonymous pulls of its own images. Anonymous access is read-only and
reaches only the layers that repository's own images reference, so nothing else in your
organization becomes readable, not even a layer the image shares with a private repository.
Replace repository-id with the repository's id.

**Important:**
Anyone on the internet can pull a public repository's images. You can switch it back at any time.

## Prerequisites

- Permission for `ecr:UpdateRepository` on the repository.
- In the console, also `ecr:DescribeRepositories` on it; without it the repository's page answers 404.

## Change the visibility

**Console**
1. Open **Image repositories**, then open the repository.
2. Open the **Settings** tab.
3. Under **Visibility**, choose **Make public**.
4. Type the repository's name, then choose **Make public**.

To go back, choose **Make private** under **Visibility**; it takes effect without a confirmation.

**CLI**
```sh
dcloud ecr repositories update repository-id --visibility public
```

**API**
```http
PATCH /ecr/api/repositories/repository-id
{ "visibility": "public" }
```

**Terraform**
```hcl
resource "dcloud_ecr_repository" "my_app" {
  name       = "my-app"
  visibility = "public"
}
```

## Result

Anyone can now run `docker pull <host>/my-app:v1.2.0` with no `docker login`. The repository's page
shows "This repository is public." above its tabs. Pushing still needs `ecr:PushImage`.

Credentials still decide for whoever presents them: a logged-in user whose policies do not allow
`ecr:PullImage` on the repository is refused even on a public repository; to pull anonymously, log
out first. After you make a repository private
again, a registry token already handed to an anonymous client works until it expires, at most one
hour.

## Related

- [Pull an image](pull-an-image.md)
- [Security in Container registry](security.md)
- `ecr.repositories.update` · `dcloud ecr repositories update` · `dcloud_ecr_repository`
