Local Private Registry
Server Side (Windows Host)
Section titled “Server Side (Windows Host)”IP Address: 10.71.168.126
1. Start the Private Registry
Section titled “1. Start the Private Registry”Run the registry service as a background container mapping port 5000.
docker run -d -p 5000:5000 --name registry --restart=always registry:2Note: --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)
2. Prepare the Application (main.sh)
Section titled “2. Prepare the Application (main.sh)”Create the bash script with LF (Linux) line endings.
#!/bin/bashTARGET=${1:-$DEFAULT_IP}echo "Running in $APP_ENV mode..."if [ -z "$TARGET" ]; then echo "Error: No IP address provided." exit 1fiping -c 4 "$TARGET"3. Define the Dockerfile
Section titled “3. Define the Dockerfile”FROM alpine:latestARG DEFAULT_IP_ARG=8.8.8.8ENV DEFAULT_IP=$DEFAULT_IP_ARGENV APP_ENV=ProductionWORKDIR /pingerCOPY main.sh .RUN apk add --no-cache bash iputils dos2unix && \\ dos2unix main.sh && \\ chmod +x main.shENTRYPOINT ["/bin/bash", "main.sh"]4. Build, Tag, and Push
Section titled “4. Build, Tag, and Push”Build the local image, alias it with the registry address, and upload it to the local service.
# Builddocker build -t pinger:latest .
# Tag for local registrydocker tag pinger:latest localhost:5000/pinger:latest
# Push to registry containerdocker push localhost:5000/pinger:latestClient Side (CentOS VM)
Section titled “Client Side (CentOS VM)”IP Address: 10.0.3.15 (NAT)
1. Configure Insecure Registry
Section titled “1. Configure Insecure Registry”Docker requires an explicit exception to pull over HTTP from a remote IP.
# Edit the daemon configurationsudo vi /etc/docker/daemon.jsonAdd the following content:
{ "insecure-registries" : ["10.71.168.126:5000"]}2. Restart Docker Service
Section titled “2. Restart Docker Service”Apply the configuration changes.
sudo systemctl restart docker3. Pull and Run the Image
Section titled “3. Pull and Run the Image”Retrieve the image using the Windows Host IP and execute the pinger.
# Pull from Windows Hostsudo docker pull 10.71.168.126:5000/pinger:latest
# Run and ping the Windows Host from CentOSsudo docker run --rm 10.71.168.126:5000/pinger:latest 10.71.168.126Summary Table
Section titled “Summary Table”| Component | Role | Address/Path |
|---|---|---|
| Registry | Image Storage Service | localhost:5000 (Server) / 10.71.168.126:5000 (Client) |
| Docker Engine | Execution Environment | Windows Desktop & CentOS VM |
daemon.json | Client Config | /etc/docker/daemon.json |
| Image Tag | Location Identity | 10.71.168.126:5000/pinger:latest |
Additional Practice
Section titled “Additional Practice”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