# Push and pull images

> Log in with an API key, name your image, and push and pull it with Docker.

You need Docker and the registry host. The examples use `registry.example.com`. To pull a private image, you need an account and an API key with either scope. To push, the key needs the **Read & write** scope. You can pull a public image without an account. See [API keys and CI](/api-keys.md).

## Log in

Use an API key as the password. An account has no password of its own.

```bash
docker login registry.example.com -u you@example.com
```

Docker asks for the password. Paste the key.

Docker needs a username, but Imagine ignores it. The key decides who you are.

For a script or CI job, send the key through standard input. See [Log in from a script](/api-keys.md#log-in-from-a-script).

Docker keeps the login in your credential store. Without one, it writes the key to `config.json`, base64-encoded and not encrypted. Run `docker logout registry.example.com` to remove it.

## Name your image

An image name is the registry host, the repository and a tag:

```text
registry.example.com/team/app:1.0
```

| Part | Rules |
| --- | --- |
| Repository, `team/app` | Up to 255 characters. Lowercase letters and digits, in one or more parts separated by `/`. Inside a part, you can separate letters and digits with one `.`, one `_`, two `_`, or any number of `-`. A part starts and ends with a letter or digit. |
| Tag, `1.0` | Up to 128 characters. Letters, digits, `_`, `.` and `-`. The first character is a letter, a digit or `_`. |

The repository can have as many parts as you like. One part, such as `app`, is valid too. `team/` is only part of the name: it does not create a group or limit access.

## Push

1. Tag your local image with the full name.

   ```bash
   docker tag my-image registry.example.com/team/app:1.0
   ```

2. Push it.

   ```bash
   docker push registry.example.com/team/app:1.0
   ```

You don't need to create the repository first. The first push creates it, and it starts private. An admin can make it public. See [Change visibility](/manage-images.md#change-visibility).

Any **Read & write** key can push to any repository. Pushing a tag that already exists moves that tag to the new image, without a warning. The old image stays in the registry and can still be pulled by digest.

## Pull by tag

```bash
docker pull registry.example.com/team/app:1.0
```

Docker uses the `latest` tag when you leave the tag out. Imagine doesn't create `latest` for you. Push it like any other tag.

## Pull by digest

A tag can move. A digest always names the same image. Docker prints the digest after a push or pull, and the image's page in Imagine shows it for every tag.

```bash
docker pull registry.example.com/team/app@sha256:<digest>
```

Replace `<digest>` with the 64-character value.

## Private and public pulls

| Action | Private repository | Public repository |
| --- | --- | --- |
| Pull | Needs a key with either scope | Works without logging in |
| Push | Needs a **Read & write** key | Needs a **Read & write** key |

A key can pull every private repository in the registry. Access is not set per repository.

Pulls also need access to the S3 host. Imagine sends the client there to download layers. Ask the person who hosts the registry for its address if your network allows only listed hosts.

## Multi-platform images

Imagine accepts multi-platform image indexes and shows their platforms on the image's page. Pushing and pulling them with a real Docker client has not been tested. For other clients and features, see [Registry compatibility](/registry-compatibility.md).

## Common errors

Docker puts its own words around the registry's message. Look for the code or message below.

| Code and message | What it means | What to do |
| --- | --- | --- |
| `UNAUTHORIZED`, `credentials are not valid` | The key is wrong, expired or revoked, or its owner was removed or banned. | Create a new key, then log in again. |
| `UNAUTHORIZED`, `authentication required` | The request has no login, or its registry token is not valid. | Log in. If you already did, run `docker logout` for the host and log in again. |
| `UNAUTHORIZED`, `insufficient scope` | Your login does not allow this: a **Read** key is used to push, or you are not logged in. Without a login, a private repository and one that does not exist give the same answer. | Check the name, then log in with a key that has the right scope. |
| `NAME_INVALID`, or Docker refuses the name itself | The repository name breaks the [rules](#name-your-image). | Rename the image. |
| `MANIFEST_UNKNOWN` | The tag or digest is not in this repository. | Check the name and tag on the image's page. |
| `SIZE_INVALID`, `blob exceeds … bytes` | One layer is over the registry's limit. The default is 16 GiB. | Make the layer smaller, or ask the host to raise the limit. |

A wrong or expired login also blocks pulls from public repositories, because Imagine refuses the login before it looks at the repository. Run `docker logout registry.example.com`, then pull again.

If a push or pull fails for another reason, send [Troubleshooting](/troubleshooting.md) to the person who hosts the registry.
