How to Use Vultr Container Registry with Docker

Updated on July 25, 2024
How to Use Vultr Container Registry with Docker header image

Introduction

Docker is a container orchestration platform that lets you build, ship, and deploy applications with a consistent environment. Containers are standardized lightweight packages that include necessary components such as dependencies, libraries, system tools, code, and runtime resources needed to run an application.

This article explains how to use a Vultr Container Registry with Docker to develop, build, and run containerized applications.

Prerequisites

Before you begin:

Generate a Vultr Container Registry Docker Configuration

  1. Open the Vultr Customer Portal.

  2. Click Products on the main navigation menu and select Container Registry.

  3. Click your Vultr Container Registry to open the management panel.

    Manage a Vultr Container Registry

  4. Navigate to the Docker/Kubernetes tab.

  5. Enter your desired configuration expiry time in the Expires (in seconds) field, and click Push Access in the Docker Credentials section to enable push privileges to the registry.

  6. Click Generate Docker Config JSON to generate a new docker.json configuration.

    Generate a new Vultr Container Registry Docker Config JSON

  7. Select and copy all generated configuration contents to your clipboard for application in your config.json file.

Log in to the Vultr Container Registry using Docker

Docker uses a config.json file in your .docker user home directory to authenticate and store your container registry information. Follow the steps below to log in to your Vultr Container Registry using Docker by applying the generated JSON configuration on your server.

  1. Navigate to your user home directory.

    console
    $ cd
    
  2. Create a new .docker directory.

    console
    $ mkdir .docker
    
  3. Switch to the directory.

    console
    $ cd .docker
    
  4. Create a new config.json configuration file to store your Docker registry information.

    console
    $ nano config.json
    
  5. Add your generated Vultr Container Registry JSON configuration to the file.

    json
    { "auths": { "sjc.vultrcr.com": { "auth": "YOUR-REGISTRY-JSON-KEY=" } }, "status": "OK" }
    

    Save and close the file.

    The above configuration creates a new Vultr Container Registry authentication method for use with Docker to pull and push container images on the server. When using multiple registries, modify the file to include new registry configurations to use with Docker.

    You have configured Docker to authenticate and use your Vultr Container Registry information on the server. To apply similar configurations without directly modifying the file, use the docker login command.

    console
    $ docker login https://sjc.vultrcr.com/example -u exampleuser -p registrypassword
    

    When successful, your output should look like the one below:

    Login Succeeded

Build a Sample Docker Image

  1. Create a new project directory docker-test to store your sample application configurations.

    console
    $ mkdir docker-test
    
  2. Switch to the directory.

    console
    $ cd docker-test
    
  3. Create a Dockerfile configuration using a text editor such as Nano.

    console
    $ nano Dockerfile
    
  4. Add the following configurations to the file.

    dockerfile
    FROM python:3.9-slim
    WORKDIR /app
    COPY . /app
    CMD ["echo", "Hello World! Welcome to the Vultr Container Registry"]
    

    Save and close the file.

    The above Docker build context creates a new container using the official Python runtime image and outputs a Hello, World prompt when the container starts.

  5. Build a new container image using the Dockerfile configuration and all directory files.

    console
    $ docker build -t hello-world .
    
  6. View all Docker images on the server and verify that the new hello-world image is available.

    console
    $ docker images
    

    Output:

    REPOSITORY                            TAG       IMAGE ID       CREATED          SIZE
    hello-world                           latest    6df51f141bfc   28 seconds ago   126MB

Tag Docker Images with Vultr Container Registry Repository Tags

  1. Tag the hello-world docker with your Vultr Container Registry tag. For example,

    console
    $ docker tag hello-world sjc.vultrcr.com/example/hello-world
    
  2. View all available Docker images and verify the new registry tag.

    console
    $ docker images
    

    Output:

    REPOSITORY                            TAG       IMAGE ID       CREATED              SIZE
    hello-world                           latest    d2c94e258dcb   About a minute ago   126MB
    sjc.vultrcr.com/example/hello-world   latest    d2c94e258dcb   About a minute ago   126MB
  3. Run the tagged container image using Docker CLI to test and verify that a Hello World! Welcome to the Vultr Container Registry message displays in your output.

    console
    $ docker run sjc.vultrcr.com/example/hello-world
    

    Output:

    Hello World! Welcome to the Vultr Container Registry

Push Docker Images to the Vultr Container Registry

  1. Push your tagged Docker image to the Vultr Container Registry.

    console
    $ docker push sjc.vultrcr.com/example/hello-world
    

    When successful, your output should be similar to the one below.

    Using default tag: latest
    The push refers to repository [sjc.vultrcr.com/example/hello-world]
    541f9a9184a4: Pushed 
    d72077a87a04: Pushed 
    e25966a5c9f4: Pushed 
    53451a08b688: Pushed 
    57f5b08e62c4: Pushed 
    bfc9081d1eb2: Pushed 
    1f00ff201478: Pushed 
    latest: digest: sha256:fb4b66c08b0e6d767a43f79f86765a43c3e980ba6c07b73c9e20b7a0255252c9 size: 1783
  2. Access your Vultr Container Registry panel, click Repositories, and verify that the new container repository is available.

    View Vultr Container Registry Repositories

Pull and Deploy Images Vultr Container Registry Images with Docker

  1. Pull the container image from the Vultr Container Registry to your Docker server.

    console
    $ docker pull sjc.vultrcr.com/example/hello-world
    
  2. Deploy a new Docker container using the Vultr Container Registry image.

    console
    $ docker run -d sjc.vultrcr.com/example/hello-world
    

    Verify that the application runs correctly with a Hello World! Welcome to the Vultr Container Registry message in your output similar to the one below:

    Hello World! Welcome to the Vultr Container Registry

Conclusion

You have set up and published container images to your Vultr Container Registry with Docker. You can build and deploy multiple Docker images to your Vultr Container Registry by creating unique tags for each repository. Periodically monitor or update your repository features such as public visibility to allow users to pull and use your container images.