# registry

Docker Registry is a service for storing and distributing Docker images. It allows you to host your private Docker images securely. The most common registry is Docker Hub, but you can also set up your private registry using Docker Registry or use cloud-based registries like Google Container Registry, AWS Elastic Container Registry (ECR), or Azure Container Registry (ACR). Here's a guide on using Docker Registry:

#### Using Docker Hub:

**1. Create a Docker Hub Account:**

* If you don't have a Docker Hub account, [sign up](https://hub.docker.com/) for a free account.

**2. Log in to Docker Hub:**

* Log in to Docker Hub using the `docker login` command in your terminal.

```bash
docker login
```

You'll be prompted to enter your Docker Hub username and password.

**3. Tag Your Image:**

* Before pushing an image to Docker Hub, you need to tag it with your Docker Hub username and the repository name.

```bash
docker tag local-image:tag username/repository:tag
```

**4. Push the Image to Docker Hub:**

* Push the tagged image to Docker Hub.

```bash
docker push username/repository:tag
```

Replace `username` with your Docker Hub username and `repository` with the name of your Docker Hub repository.

#### Using Private Docker Registry:

**1. Run a Docker Registry:**

* You can run a private Docker Registry by executing the following command:

```bash
docker run -d -p 5000:5000 --name registry registry:2
```

This command starts a Docker Registry container on port 5000.

**2. Tag Your Image:**

* Tag your local image with the address of your private registry.

```bash
docker tag local-image:tag localhost:5000/repository:tag
```

Replace `repository` with the name you want to give to your repository.

**3. Push the Image to Your Registry:**

* Push the tagged image to your private registry.

```bash
docker push localhost:5000/repository:tag
```

Ensure that your Docker Registry container is running and reachable.

#### Using Cloud-Based Registries (e.g., AWS ECR):

**1. Create an ECR Repository:**

* If you are using AWS ECR, create a repository using the AWS Management Console or AWS CLI.

```bash
aws ecr create-repository --repository-name my-repository
```

**2. Authenticate Docker to Your ECR Registry:**

* Run the following AWS CLI command to authenticate Docker to your ECR registry.

```bash
aws ecr get-login-password --region region | docker login --username AWS --password-stdin account-id.dkr.ecr.region.amazonaws.com
```

Replace `region` and `account-id` with your AWS region and account ID.

**3. Tag and Push Your Image to ECR:**

* Tag your local image with your ECR repository URI and push it.

```bash
docker tag local-image:tag account-id.dkr.ecr.region.amazonaws.com/my-repository:tag
docker push account-id.dkr.ecr.region.amazonaws.com/my-repository:tag
```

#### Pulling Images from a Registry:

**1. From Docker Hub:**

* Pull an image from Docker Hub using the `docker pull` command.

```bash
docker pull username/repository:tag
```

**2. From a Private Registry:**

* Pull an image from a private registry using the `docker pull` command.

```bash
docker pull localhost:5000/repository:tag
```

Make sure to replace `repository` and `tag` with the appropriate values.

**3. From a Cloud-Based Registry (e.g., AWS ECR):**

* Pull an image from a cloud-based registry using the `docker pull` command.

```bash
docker pull account-id.dkr.ecr.region.amazonaws.com/my-repository:tag
```

Replace `account-id`, `region`, `my-repository`, and `tag` with the appropriate values.

Docker Registry provides a way to manage and distribute your Docker images efficiently. Whether using Docker Hub, a private registry, or a cloud-based registry, the basic workflow involves tagging your images, pushing them to the registry, and pulling them when needed. Always consider security best practices when dealing with private registries, including authentication and image scanning.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://a7246c5516ab4c80cdfe21ca2be3e40c.gitbook.io/docker-basics/registry.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
