Docker Hub is super neat and very intuitive and offers a great deal of functionality for free.
But what if we need more privacy? Or your client wants to use its own server.
If that’s the case, we can make your own Docker Registry.
So how do we do that?
Well, we can set up the registry in two different ways:
- directly with the Docker command
- using Docker compose
Install Docker before pefomorming any operations described here.
Create a directory to permanently store images.
$ sudo mkdir -p /srv/rcherara-registry/data
Start a local registry container.
$ sudo docker run -d -p 5000:5000 --restart=always --name registry \ -v /certs:/certs \ -e REGISTRY_HTTP_TLS_CERTIFICATE=/certs/domain.crt \ -e REGISTRY_HTTP_TLS_KEY=/certs/domain.key \ registry:2
If we use default folder for volume :
$ docker run -d -p 5000:5000 --restart=always -n registry -e REGISTRY_HTTP_ADDR=0.0.0.0:5000 registry:latest
$ docker run -d -p 50000:5000 --restart always --name rcherara-docker-registry registry:latest
with new volume directory
$ docker run -it -d -p 5000:5000 --restart always --name rcherara-docker-registry registry:latest -v /srv/rcherara-registry/data:/var/lib/registry
Now we can navigate to http://localhost:5000/v2/_catalog and see for yourself that your registry is up and running and that you have no repositories pushed to it.
You should be able to see something like this:
http://vm-rcherara-devops:5000/v2/_catalog
The same thing can be done with Docker Compose
But, top the registry we’ve spin up before with docker stop my-registry
and docker rm my-registry
to remove the attached container.
After that run docker-compose up -d
in the /Infrastructure/Registry folder.
version: '3.0'
services:
rcherara-registry:
image: registry:latest
container_name: rcherara-docker-registry
volumes:
- registry:/var/lib/registry
ports:
- "50000:5000"
restart: unless-stopped
volumes:
registry:
Test the docker registry
Now, use it from within Docker:
Get a sample image, tag then push to the registry.
$ docker pull ubuntu
$ docker tag ubuntu localhost:5000/ubuntu
$ docker push localhost:5000/ubuntu