⚡️ Using Custom Registry
Let's use the custom registry we created yesterday.
304 Words Reading Time: 1 Minute, 22 Seconds
09-22-2024 12:40 +0000
On the previous post, we have seen how to create a custom registry. Now, we will see how to use it.
Adding custom registry to Portainer
Right now, I am using Portainer to visualize and organize my containers. Portainer by default can pull images from the Docker Hub. Let’s add our brand new registry to Portainer.
- Navigate to Administration > Registries
- Click on + Add registry
- In my case, select Custom registry
- Fill in the details
Now, let’s push and image
Let’s use this very Hugo blog you are reading right as an example. We want to build it, and push it to our brand new registry.
#!/bin/bash
set -e # Exit immediately if a command exits with a non-zero status
# Clone or update the theme
if [ -d "themes/hermit-v2" ]; then
# If the theme directory exists, update it
echo "Updating theme..."
cd themes/hermit-v2
git pull origin main
cd ../..
else
# If the theme directory does not exist, clone it
echo "Cloning theme..."
git clone https://github.com/1bl4z3r/hermit-V2 themes/hermit-v2
fi
# Build the Hugo site, ensuring it fails if something goes wrong
echo "Building Hugo site..."
hugo || { echo "Hugo build failed"; exit 1; }
# Build the Docker image with the correct platform (x86_64/amd64)
echo "Building Docker image..."
docker build --platform linux/amd64 -t registry.pops.cafe/pops-web:latest .
# Stop and remove the running container if it exists
if [ $(docker ps -q --filter "name=hugo-server") ]; then
echo "Stopping existing container..."
docker stop hugo-server
docker rm hugo-server
fi
# Push the Docker image to the private registry
echo "Pushing Docker image to registry..."
docker login registry.pops.cafe -u $registerUser -p $registerPassword
docker push registry.pops.cafe/pops-web:latest
echo "Build and push complete!"
Nice! Now we have our image in the registry. 🎉 Tomorrow, we will find a way to deploy it automatically when pushed. See you then! 👋