Skip to content

Local Private Registry


IP Address: 10.71.168.126

Run the registry service as a background container mapping port 5000.

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

Note: --restart=always make sure that container is always running even if it is crashed it automatically restarts..

  • Container crashes → ✅ Docker restarts it
  • Server reboots → ✅ Docker starts it again
  • You run docker stop my-registry → ❌ It stays stopped (until you manually start it again)

Create the bash script with LF (Linux) line endings.

#!/bin/bash
TARGET=${1:-$DEFAULT_IP}
echo "Running in $APP_ENV mode..."
if [ -z "$TARGET" ]; then
echo "Error: No IP address provided."
exit 1
fi
ping -c 4 "$TARGET"
FROM alpine:latest
ARG DEFAULT_IP_ARG=8.8.8.8
ENV DEFAULT_IP=$DEFAULT_IP_ARG
ENV APP_ENV=Production
WORKDIR /pinger
COPY main.sh .
RUN apk add --no-cache bash iputils dos2unix && \\
dos2unix main.sh && \\
chmod +x main.sh
ENTRYPOINT ["/bin/bash", "main.sh"]

Build the local image, alias it with the registry address, and upload it to the local service.

Terminal window
# Build
docker build -t pinger:latest .
# Tag for local registry
docker tag pinger:latest localhost:5000/pinger:latest
# Push to registry container
docker push localhost:5000/pinger:latest

IP Address: 10.0.3.15 (NAT)

Docker requires an explicit exception to pull over HTTP from a remote IP.

Terminal window
# Edit the daemon configuration
sudo vi /etc/docker/daemon.json

Add the following content:

{
"insecure-registries" : ["10.71.168.126:5000"]
}

Apply the configuration changes.

Terminal window
sudo systemctl restart docker

Retrieve the image using the Windows Host IP and execute the pinger.

Terminal window
# Pull from Windows Host
sudo docker pull 10.71.168.126:5000/pinger:latest
# Run and ping the Windows Host from CentOS
sudo docker run --rm 10.71.168.126:5000/pinger:latest 10.71.168.126

ComponentRoleAddress/Path
RegistryImage Storage Servicelocalhost:5000 (Server) / 10.71.168.126:5000 (Client)
Docker EngineExecution EnvironmentWindows Desktop & CentOS VM
daemon.jsonClient Config/etc/docker/daemon.json
Image TagLocation Identity10.71.168.126:5000/pinger:latest

Let practice deploying a registry server on our own. Run a registry server with name equals to my-registry using registry:2 image with host port set to 5000, and restart policy set to always.

docker run —name=my-registry -p 5000:5000 —restart=always registry:2

Now its time to push some images to our registry server. Let’s push two images for now .i.e. nginx:latest and httpd:latest.

Note: Don’t forget to pull them first.

To check the list of images pushed , use curl -X GET localhost:5000/v2/_catalog

docker pull nginx:latest

docker pull httpd:latest

docker tag nginx:latest localhost:5000/nginx:latest

docker tag httpd:latest localhost:5000/httpd:latest

docker push localhost:5000/nginx

docker push localhost:5000/httpd

curl -X GET localhost:5000/v2/_catalog {“repositories”:[“httpd”,“nginx”]}

Let’s remove all the dangling images we have locally. Use docker image prune -a to remove them. How many images do we have now?

Note: Make sure we don’t have any running containers except our registry-sever.

To get list of images use: docker image ls

docker image prune -a

Now we can pull images from our registry-server as well. Use docker pull [server-addr/image-name] to pull the images that we pushed earlier.

In our case we can use: docker pull localhost:5000/nginx