Creating a Docker Registry
Creating a docker registry is rather straightforward, but you may need to do some tweaking of your docker installation in order to get it working as indicated below.
Let’s assume that you already have docker up and running on your machine.
We are going to set up a Docker registry on our local server. This
server will not have a secure connection and will only be used
internally, so we will need to allow this access by creating a file in
/etc/docker
called daemon.json to designate
this:
{
"insecure-registries":[
"localhost:5000"
]
}
Don’t forget to restart the docker daemon after making this change.
Now, create a docker volume that will persist your registry data when it goes offline:
# docker volume create /mnt/registry
This next part is optional. You can use whatever means you want to download and start the container: Create a script to download the image and start the container:
# mkdir /mnt/registry
# cat >start-registry.sh <<"EOF"
> docker run -d \
> -p 5000:5000 \
> --restart=always \
> --name registry \
> -v /mnt/registry:/var/lib/registry \
> registry:2
> EOF
Now start the registry (using the above script):
# ./start-registry.sh
Now, let’s test it by pushing a sample hello-world image to the registry:
$ docker tag hello-world:latest localhost:5000/hello-world:latest
$ docker push localhost:5000/hello-world:latest
The push refers to repository [localhost:5000/hello-world]
e07ee1baac5f: Pushed
latest: digest: sha256:f54a58bc1aac5ea1a25d796ae155dc228b3f0e11d046ae276b39c4bf2f13d8c4 size: 525
NOTE: If you are pushing to this registry from another server you
need to add the following to /etc/docker/daemon.json
and
restart docker before you will be able to do a push
(replace localhost with the IP address of the server that’s
running the registry):
{
"insecure-registries":[
"localhost:5000"
]
}
Now we can use curl to list the repositories in the registry:
curl localhost:5000/v2/_catalog
More information about creating a docker registry can be found here and if you’re interested in setting up authentication for your private registry you can find more information here