# Getting started with Container registry

Create a repository, log in with docker, push an image, read its scan, and delete it all again.

You need Docker on a Linux or macOS machine and an image to push. Replace
org-example1234.ecr.example.com with your registry host (the console shows it as
**Image URI** on the repository's page) and my-app with the repository name. In the CLI
steps, repository-id is the `id` the create command answers with, and
manifest-id is the image's `manifest.id` in the image list.

## Prerequisites

- `ecr:CreateRepository`, `ecr:GetAuthorizationToken`, `ecr:PushImage`, `ecr:PullImage`,
  `ecr:DescribeRepositories`, `ecr:ListImages`, `ecr:GetScanResults` and
  `ecr:DeleteRepository`. The `AdministratorAccess` policy has all of them.

## Step 1: Create a repository

**Console**
1. Open **Container registry**, then choose **Create image repository**.
2. For **Repository name**, enter my-app.
3. Choose **Create image repository**.

The repository's page opens on its **Images** tab.

**CLI**
```sh
dcloud ecr repositories create --name my-app
```

## Step 2: Log in

**Console**
1. On the repository's page, open the **Push commands** tab.
2. Choose **Generate a login token**.
3. Run the `docker login` command it shows, and paste the token at the `Password:` prompt.

**CLI**
```sh
dcloud ecr auth login-token
```

Run `docker login org-example1234.ecr.example.com -u token` and paste the `token` from
the answer at the `Password:` prompt.

## Step 3: Push and pull

```sh
docker tag my-image:latest org-example1234.ecr.example.com/my-app:v1.2.0
docker push org-example1234.ecr.example.com/my-app:v1.2.0
docker pull org-example1234.ecr.example.com/my-app:v1.2.0
```

You pay for the stored layers from now on.

## Step 4: Read the scan

A pushed image is scanned on its own.

**Console**
1. Open the **Images** tab. The **Vulnerabilities** column shows **Scanning** while the scan
   runs, then the worst severity found or **Clean**.
2. Choose the result to open the scan report.

**CLI**
```sh
dcloud ecr images list repository-id
dcloud ecr images latest-scan repository-id manifest-id
```

`manifest.id` of the image's row is the manifest id.

## Clean up

Deleting the repository deletes its images.

**Console**
1. On the repository's page, open the **Danger zone** tab.
2. Choose **Delete repository**, type the repository's name, then choose **Delete repository**.

**CLI**
```sh
dcloud ecr repositories delete repository-id
```

## Next steps

- [Push an image](push-an-image.md)
- [Make tags immutable](make-tags-immutable.md)
- [Set a lifecycle policy](set-a-lifecycle-policy.md)
