How to Use Vultr Container Registry with Docker
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:
Deploy a Vultr Container Registry.
Deploy an instance using Vultr's GPU Marketplace App
Access the server using SSH.
Start the Docker service.
console$ sudo systemctl start docker
Generate a Vultr Container Registry Docker Configuration
Open the Vultr Customer Portal.
Click Products on the main navigation menu and select Container Registry.
Click your Vultr Container Registry to open the management panel.
Navigate to the Docker/Kubernetes tab.
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.
Click Generate Docker Config JSON to generate a new
docker.json
configuration.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.
Navigate to your user home directory.
console$ cd
Create a new
.docker
directory.console$ mkdir .docker
Switch to the directory.
console$ cd .docker
Create a new
config.json
configuration file to store your Docker registry information.console$ nano config.json
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
Create a new project directory
docker-test
to store your sample application configurations.console$ mkdir docker-test
Switch to the directory.
console$ cd docker-test
Create a Dockerfile configuration using a text editor such as Nano.
console$ nano Dockerfile
Add the following configurations to the file.
dockerfileFROM 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.Build a new container image using the Dockerfile configuration and all directory files.
console$ docker build -t hello-world .
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
Tag the
hello-world
docker with your Vultr Container Registry tag. For example,console$ docker tag hello-world sjc.vultrcr.com/example/hello-world
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
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
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
Access your Vultr Container Registry panel, click Repositories, and verify that the new container repository is available.
Pull and Deploy Images Vultr Container Registry Images with Docker
Pull the container image from the Vultr Container Registry to your Docker server.
console$ docker pull sjc.vultrcr.com/example/hello-world
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.