Contents

Docker Registry

Website Visitors:

Docker Registry

A Docker registry is a storage and distribution system for Docker images. It allows you to store and manage Docker images, which are used to create Docker containers. Docker images are the blueprints for containers, containing everything needed to run a containerized application, including the code, runtime, libraries, environment variables, and configuration files.

A Docker registry can be public or private. Public registries, such as Docker Hub, allow anyone to store and access Docker images. Private registries are used within organizations to securely store and share proprietary Docker images.

Examples of Docker registries include:

  1. Docker Hub: Docker Hub is the official public registry for Docker images. It hosts a vast number of public images that can be used by anyone.

  2. Amazon Elastic Container Registry (ECR): Amazon ECR is a fully managed Docker container registry provided by Amazon Web Services (AWS). It allows you to store, manage, and deploy Docker images on AWS.

  3. Google Container Registry (GCR): Google Container Registry is a private Docker registry provided by Google Cloud Platform. It allows you to store and manage Docker images securely on Google Cloud.

  4. Azure Container Registry: Azure Container Registry is a private Docker registry provided by Microsoft Azure. It enables you to store and manage Docker images for container deployments on Azure.

These are just a few examples of Docker registries that provide storage and distribution capabilities for Docker images, helping developers and organizations manage their containerized applications effectively.

Docker Image naming convention

In Docker, image naming conventions are important for identifying and referencing Docker images. Docker image names typically follow the format:

1
2
3
registry/repository:tag

Ex: docker.io/nginx/nginx

Here’s what each part of the naming convention represents:

  1. Registry: The registry is an optional part of the image name that specifies where the image is located. If no registry is specified, Docker will default to Docker Hub. Other examples of registries include Amazon ECR, Google Container Registry, and Azure Container Registry.

  2. Repository: The repository is the name of the image within the registry. It helps organize images within the registry. For example, if you have an image for a web server, you might name the repository webserver.

  3. Tag: The tag is a way to version your images. It is optional but recommended for managing different versions of the same image. Tags can be used to differentiate between different builds, releases, or configurations of an image. Common tags include latest, version numbers, or specific release names.

Here are a few examples of Docker image names following the naming convention:

  • nginx:latest: This refers to the latest version of the Nginx web server image on Docker Hub.
  • myregistry.com/myapp:1.0: This refers to version 1.0 of the myapp image stored in a private registry at myregistry.com.
  • ubuntu:20.04: This refers to the Ubuntu 20.04 image on Docker Hub.

By following a consistent naming convention for Docker images, you can easily identify, reference, and manage your images across different environments and registries.

Private Registry

A private registry in the context of Docker is a secure storage and distribution system for Docker images that is used within an organization or by an individual. Images that should not be released to public, are hosted under private registry. Unlike public registries like Docker Hub, a private registry is not accessible to the general public and is typically used to store proprietary or sensitive Docker images.

Popular private registry solutions include:

  • Amazon Elastic Container Registry (ECR): A fully managed Docker container registry provided by AWS.
  • Google Container Registry (GCR): A private Docker registry provided by Google Cloud Platform.
  • Azure Container Registry: A private Docker registry provided by Microsoft Azure.

Overall, private registries play a crucial role in enabling organizations to securely store, manage, and distribute Docker images while maintaining control over their containerized applications and data.

Creating a Docker Private Registry

Docker registry is available as an image in docker hub. Name of the image is Registry. It runs on port 5000 by default.

Creating a Docker Private Registry:

  1. Install Docker Registry: You can install the Docker registry by running the following command:

    1
    
    docker run -d -p 5000:5000 --restart=always --name registry registry:2
    

    This will start a Docker registry container on port 5000.

  2. Configure the Registry: You can configure the registry by creating a config.yml file and mounting it to the container. For example:

     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    
    version: 0.1
    log:
      fields:
        service: registry
    storage:
      filesystem:
        rootdirectory: /var/lib/registry
    http:
      addr: :5000
      headers:
        X-Content-Type-Options: [nosniff]
    health:
      storagedriver:
        enabled: true
        interval: 10s
        threshold: 3
    

    You can then start the registry with the configuration file:

    1
    
    docker run -d -p 5000:5000 --restart=always --name registry -v /path/to/config.yml:/etc/docker/registry/config.yml registry:2
    

Accessing the Docker Private Registry:

  1. Tag an Image: Before you can push an image to the private registry, you need to tag it with the registry’s address. For example:

    1
    
    docker tag my-image localhost:5000/my-image
    
  2. Push the Image: Now you can push the image to the private registry:

    1
    
    docker push localhost:5000/my-image
    
  3. Pull the Image: To pull the image from the private registry, you can use the following command:

    1
    2
    3
    
    docker pull localhost:5000/my-image
    
    docker pull 192.168.1.1:5000/my-image
    

Examples:

  1. Pushing an Image to the Private Registry:

    1
    2
    3
    4
    5
    
    # Tag the image
    docker tag nginx localhost:5000/my-nginx
    
    # Push the image
    docker push localhost:5000/my-nginx
    
  2. Pulling an Image from the Private Registry:

    1
    2
    
    # Pull the image
    docker pull localhost:5000/my-nginx
    
  3. Listing Images in the Private Registry:

    1
    2
    
    # List images in the registry
    curl http://localhost:5000/v2/_catalog
    
  4. Deleting an Image from the Private Registry:

    1
    2
    
    # Delete an image
    curl -X DELETE http://localhost:5000/v2/my-image/manifests/sha256:abcd1234
    

Remember, these examples use localhost:5000 as the registry address. If you’re using a different address, replace it accordingly.

Accessing Private Registry

To access a private Docker registry, you need to authenticate yourself and configure Docker to use the credentials required to pull or push images from/to the private registry. Here are the general steps to access a private Docker registry:

  1. Login to the Private Registry: Use the docker login command to authenticate yourself with the private registry. You will be prompted to enter your username and password or any other authentication method required by the registry.

    1
    
    docker login <registry-url>
    
  2. Tag the Image: If you want to push an image to the private registry, you need to tag the image with the private registry URL. This is done using the docker tag command.

    1
    
    docker tag <image-name> <registry-url>/<image-name>
    
  3. Push or Pull Images: Once you are authenticated and the image is tagged correctly, you can push or pull images from the private registry using the standard docker push and docker pull commands.

    To push an image:

    1
    
    docker push <registry-url>/<image-name>
    

    To pull an image:

    1
    
    docker pull <registry-url>/<image-name>
    
  4. Use Docker Configuration File: If you want to avoid entering credentials every time you interact with the private registry, you can store your credentials in the Docker configuration file (~/.docker/config.json). This file can store authentication details for multiple registries.

  5. Using Docker Compose: If you are using Docker Compose to manage your containers, you can specify the authentication details for the private registry in the docker-compose.yml file under the image field.

By following these steps, you can access a private Docker registry securely and manage your Docker images within your organization’s infrastructure. Remember to keep your credentials secure and follow best practices for managing access to private registries.

Your inbox needs more DevOps articles.

Subscribe to get our latest content by email.