LAB-05: Running Docker Free Local Registry, Tagging Container, Pushing to Local Registry, Pulling From Local Registry
This scenario shows how to run Docker local free registry, tag container, push into the local registry and pull from the registry.
- Pull 'Registry' image from Docker Hub:
docker image pull registry
- Run container using 'Registry' image: (-p: port binding [hostPort]:[containerPort], -d: detach mode (running background), -e: change environment variables status)
docker container run -d -p 5000:5000 --restart always --name localregistry -e REGISTRY_STORAGE_DELETE_ENABLED=true registry
- Run registry container with binding mount (-v) and without getting error 500 (REGISTRY_VALIDATION_DISABLED=true):
docker run -d -p 5000:5000 --restart=always --name registry -v /home/docker_registry:/var/lib/registry -e REGISTRY_STORAGE_DELETE_ENABLED=true -e REGISTRY_VALIDATION_DISABLED=true -e REGISTRY_HTTP_ADDR=0.0.0.0:5000 registry:2
- Open a browser: (localregistry runs on 127.0.0.1:5000)
http://127.0.0.1:5000/v2/_catalog
- To push the image to localregistry, firstly change the name of the image using 'tag', add '127.0.0.1:5000/' as a prefix of the image to push localregistry:
docker image tag [sourceImageName] [targetImageName]
docker image tag alpine 127.0.0.1:5000/alpine:latest (pushing alpine image)
docker image push 127.0.0.1:5000/alpine:latest
docker image tag busybox 127.0.0.1:5000/busybox:latest
docker image push 127.0.0.1:5000/busybox:latest
- Refresh the browser to see latest status:
- To download from localregistry:
docker image pull [imageName]
docker image pull 127.0.0.1:5000/busybox:latest
- There are different ways of deleting images from localregistry:
- using curl DELETE, (https://betterprogramming.pub/cleanup-your-docker-registry-ef0527673e3a)
- removing the file from the filesystem,
- running rm command in the container (I prefer this method, it absolutely works):
docker exec -it localregistry rm -rf /var/lib/registry/docker/registry/v2/repositories/alpine
docker exec -it localregistry rm -rf /var/lib/registry/docker/registry/v2/repositories/busybox
- After deletion, as expected, when trying pulling image from localregistry, it is not found:
- Docker registy stores both Windows and Linux Container at the same time:
docker run -d -p 5000:5000 --restart=always --name registry -v /home/docker_registry:/var/lib/registry -e REGISTRY_STORAGE_DELETE_ENABLED=true -e REGISTRY_VALIDATION_DISABLED=true -e REGISTRY_HTTP_ADDR=0.0.0.0:5000 registry:2
- Switch Docker Desktop to Windows Container
- Please add "IP:5000" in your Docker Desktop (Settings>Docker Engine>"insecure-registries")
- Tagging Image:
docker tag mcr.microsoft.com/windows/nanoserver:1909 {IPofRegistryServer}:5000/windows-nanoserver
- Pushing Image:
docker push {IPofRegistryServer}:5000/windows-nanoserver
- Browsing: IP:5000/v2/_catalog