Difference between Docker registry and repository - docker

I'm confused as to the difference between docker registries and repositories. It seems like the Docker documentation uses the two words interchangeably. Also, repositories are sometimes referred to as images, such as this from their docs:
In order to push a repository to its registry, you need to have named
an image or committed your container to a named image as we saw here.
Now you can push this repository to the registry designated by its
name or tag.
How can you push a repository to a registry? Aren't you pushing the image to the repository?

Docker registry is a service that is storing your docker images.
Docker registry could be hosted by a third party, as public or private registry, like one of the following registries:
Docker Hub,
Quay,
Google Container Registry,
AWS Container Registry
or you can host the docker registry by yourself
(see https://docs.docker.com/ee/dtr/ for more details).
Docker repository is a collection of different docker images with same name, that have different tags. Tag is alphanumeric identifier of the image within a repository.
For example see https://hub.docker.com/r/library/python/tags/. There are many different tags for the official python image, these tags are all members of the official python repository on the Docker Hub. Docker Hub is a Docker Registry hosted by Docker.
To find out more read:
https://docs.docker.com/registry/
https://github.com/docker/distribution

From the book Using Docker, Developing and deploying Software with Containers
Registries, Repositories, Images, and Tags
There is a hierarchical system for storing images.
The following terminology is used:
Registry
A service responsible for hosting and distributing images. The default registry is the Docker Hub.
Repository
A collection of related images (usually providing different versions of the same application or service).
Tag
An alphanumeric identifier attached to images within a repository (e.g., 14.04 or stable ).
So the command docker pull amouat/revealjs:latest will download the image tagged latest within the amouat/revealjs repository from the Docker Hub registry.

Complementing the information:
You usually push a repository to a registry (and all images that are part of it). But you can push a single image to a registry. In all cases, you use docker push.
An image has a 12-hex-digit Image ID, but is also identified by: namespace/repo-name:tag
The image full name can be optionally prefixed by the registry host name and port: myregistryhost:5000/namespace/repo-name:tag
A common naming convention is to use your registry user-name as what I called "namespace".

A docker repository is a cute combination of registry and image.
docker tag foo <registry>/<image>:<tag>
is the same as
docker tag foo <repository>:<tag>

Docker Registry is a service, which you can either host yourself (Trusted and Private) or you can let docker hub be the host for this service. Usually, if your software is commercial, you will have hosted this as a "Private and Trusted" registry. For Java Developers, this is somewhat analogous to Maven Artifactory setup.
Docker Repository is a set of "Tagged" images. An example is that you might have tagged 5 of ubuntu:latest images:
a) Nano editor (image1_tag:v1)
b) A specific software 1 (image1_tag:v2)
c) Sudo (image1_tag:v3)
d) apache http daemon (image1_tag:v4)
e) tomcat (image1_tag:v5)
You can use docker push command to push each of the above images to your repository. As long as the repository names match, they will be pushed successfully, and appear under your chosen repository and correctly tagged.
Now, your question is, "So where is this repository hosted/who is managing the service"? That is where Docker Registry comes into picture. By default you will get a docker hub registry (Open Source) which you can use to keep your private/public repository. So without any modification, your images will be pushed to your private repository in docker hub. An example output when you pushing your image tags are the following:
docker#my-docker-vm:/$ docker push mydockerhub/my-helloworld-repo:my_tag
The push refers to repository [docker.io/mydockerhub/my-helloworld-repo]
bf41e934d39d: Pushed
70d93396f87f: Pushed
6ec525dfd060: Pushed
705419d10b13: Pushed
a4aaef726d02: Pushed
04964fddc946: Pushed
latest: digest: sha256:eb93c92351bce785aa3ec0de489cfeeaafd55b7d90adf95ecea02629b376e577 size: 1571
docker#my-docker-vm:/$
And if you type immediately docker images --digests -a you can confirm that your pushed image tags are now showing new signature against the private repository managed by docker hub registry.

A Docker image registry is the place to store all your Docker images. The image registry allows you to push and pull the container images as needed.
Registries can be private or public. When the registry is public, the images are shared with the whole world whereas in the private registry the images are shared only amongst the members of an enterprise or a team.
A registry makes it possible for the Docker daemon to easily pull and run your Docker images.

Docker Hub and other third party repository hosting services are called “registries”. A registry stores a collection of repositories.
As a registry can have many repositories and a repository can have many different versions of the same image which are individually versioned with tags.

The confusion starts with this definition of a tag: "An alphanumeric identifier attached to images in a repository"
I'd rather call that alphanumeric identifier that you append with a ':' a tag-suffix for now. When somebody says "'latest' is the default tag", then this kind of tag-suffix is meant.
In reality, the :latest' suffix is technically part of the tag. The entire name is a tag. All these are tags (possibly referring to the same image):
myimagename
myimagename:latest
username/theirimagename:1.0
myrepo:5000/username/imagename:1.0
(I say imagename here, just to illustrate the other main source of confusion. That's the repositoryname, of course. Sorry.)
Examples:
a) When you want to name your image while building, you use docker build -t thisname ... -- that is -t for tag, (not -n for name).
b) When you want to push that image to a registry, you need to have the full URL (starting with registryname and ending with a tag-suffix) as a tag:
docker tag thisname mylocalregistry:5000/username/repoimagething:1.0
Now you push the image known as thisname by saying:
docker push mylocalregistry:5000/username/repoimagething:1.0
Naming things is hard.
Alas! A repository is not a "container" (aaargh...) where you put things in, that is what muggles think...

Related

How do you tag a Docker Manifest [duplicate]

On a private registry (myregistry.com), say I have an image tagged with 'v1.2.3'. I then push it by:
docker push myregistry.com/myimage:v1.2.3
If I want to associate another tag, say 'staging', and push that tag to my registry, I can:
docker tag myregistry.com/myimage:v1.2.3 myregistry.com/myimage:staging
docker push myregistry.com/myimage:staging
Though this works, the second docker push still runs through each image, attempting to push it (albeit skipping upload). Is there a better way just to add a remote tag?
The way you've stated, docker tag ...; docker push ... is the best way to add a tag to an image and share it.
In the specific example you've given, both tags were in the same repo (myregistry.com/myimage). In this case you can just docker push myregistry.com/myimage and by default the docker daemon will push all the tags for the repo at the same time, saving the iteration over layers for shared layers.
You can use the same process (docker tag ...; docker push ...) to tag images between repositories as well, e.g.
docker tag myregistry.com/myimage:v1.2.3 otherregistry.com/theirimage:v2
docker push otherregistry.com/theirimage
You can achieve this with docker buildx imagetools create
docker buildx imagetools create myregistry.com/myimage:v1.2.3 --tag myregistry.com/myimage:staging
this will simply download the image manifest of myregistry.com/myimage:v1.2.3 and re-tag (and push) it as myregistry.com/myimage:staging
NOTE: this will also retain the multi-platform manifest list when you "re-tag" (e.g. when your image is build for both linux/arm64 and linux/amd64). Where as the conventional docker pull/push strategy will only retain the image manifest for the platform/architecture of the system you do the pull/push from.
pull/tag/push method will have time&network costs, you can just remotely tag your image with:
only for changing TAG the answer https://stackoverflow.com/a/38362476/8430173 works , but I wanted to change the repository name too.
by many thanks to this, I changed the repoName too!
(by help of his Github project):
1- get manifests (in v2 schema)
2- post every layer.digest in the new repo
3- post config.layer
4- put whole manifest to new repo
details:
1- GET manifest from reg:5000/v2/{oldRepo}/manifests/{oldtag} withaccept header:application/vnd.docker.distribution.manifest.v2+json
2- for every layer : POST reg:5000/v2/{newRepo}/blobs/uploads/?mount={layer.digest}&from={oldRepoNameWithaoutTag}
3- POST reg:5000/v2/{newRepo}/blobs/uploads/?mount={config.digest}&from={oldRepoNameWithaoutTag}
4- PUT reg:5000/v2/{newRepo}/manifests/{newTag} with content-type header:application/vnd.docker.distribution.manifest.v2+json and body from step 1 response
5- enjoy!
For single platform images, you can use
docker pull repo:oldtag
docker tag repo:oldtag repo:newtag
docker push repo:newtag
However, there are a few downsides.
You pull all the layers even if you don't need to run the image locally.
You are dereferencing multi-platform images to your local platform.
This can be done with curl, especially if you are in the same repository (when you go across repositories, you also need to copy all the blobs). However, that has two challenges of its own:
You need to accept all of the possible media types for the image you are pulling, track the media type you received, and use that same media type when pushing the manifest back to the registry. There are at least 6 media types I'm familiar with:
a signed and unsigned docker schema v1
the common manifest and manifest list in docker schema v2
the OCI image and index
If you go across repositories, you need to parse the manifest for the included blobs, which can be recursive for docker manifest lists and OCI indexes. You may be able to do a server side blob mount to avoid pulling and pushing the blob, but that will depend on the server support. And we're also going to see anonymous blob mounts come to registries, which allows a blob mount even if you don't know the source repo on that registry (useful for everyone pushing to a cloud registry with an image based on an official docker image from Docker Hub).
Authorization gets complicated, particularly if you have bearer tokens to request and maintain between commands.
The solution I'd recommend is using a tool that handles the registry API for you. I've been working on my own tooling for this, regclient, and there are other similar projects like Google's crane and RedHat's skopeo. These should each handle the media types, copying blobs when needed, and authorization issues that would complicate the curl command.
As an example with regclient's regctl command, you'd run:
regctl image copy repo:oldtag repo:newtag
With google's crane you just do
crane tag myregistry.com/myimage:v1.2.3 staging
It works with both docker images and OCI images, no image is downloaded locally and it even skips the layer verifications, as they are guaranteed to already be in the repository.
It's even available in a docker image: gcr.io/go-containerregistry/crane
Note that there are other similar tools, like regctl or skopeo
There is a simpler method with the new experimental manifest Docker commands. It only requires downloading and uploading the manifest file (JSON overview) of an image. The commands below have been tested with the GitLab registry. First build and push a Docker image in some previous stage:
docker build -t registry.gitlab.com/<group>/<project>/<image-name>:<tag-a> .
docker push registry.gitlab.com/<group>/<project>/<image-name>:<tag-a>
Then at a later stage where the image has not been pulled:
docker manifest create registry.gitlab.com/<group>/<project>/<image-name>:<tag-b> \
registry.gitlab.com/<group>/<project>/<image-name>:<tag-a>
docker manifest push registry.gitlab.com/<group>/<project>/<image-name>:<tag-b>
You can then pull the image with the new tag. The first step did not seem to work with public Docker Hub images, but any suggestions are welcome. Additionally, to see the manifest itself, run:
docker manifest inspect registry.gitlab.com/<group>/<project>/<image-name>:<tag-a>

How do I docker buildx build into a local "registry" container

I am trying to build a multi-arch image but would like to avoid pushing it to docker hub. I've had a lot of trouble finding out how to control the export options. is there a way to make "--push" push to a registry of my choosing?
Any help is appreciated
Docker provides a container image for a registry server that you may self run even on localhost, see: Deploying a registry server.
There are other servers|services that implement the registry API (see below) but this is a good place to start.
Conventionally, images pushed|pulled default to Docker registry; unless a registry is explicitly specifed, an image e.g. your-image:your-tag defaults to docker.io/my-image:my-tag. In my opinion, it's a good practice to always include this default to be more transparent about this.
If you run Docker's registry image on localhost on the default port 5000, you'll need to take your images with localhost:5000/your-image:your-tag to ensure that when you docker push localhost:5000/your-image:your-tag, the CLI is able to determine your local registry is the intended destination.
Similarly, if you use e.g. Quay registry, images must be prefixed quay.io, Google Artifact Registry, images are prefixed ${REGION}-docker.pkg.dev/${PROJECT}/${REPOSITORY} etc.
IIRC it's not possible to push to Docker's registry (aka dockerhub) without an account so, as long as you ensure you're not logged in, you should not accidentally push images to Docker's registry.
NOTE You only need to use a registry to ease distribution of container images between machines. If you're only interested in local(host) development, you can docker run ... immediately after a successful docker build without any pushing|pulling (beyond interim images, e.g. FROM).

docker difference between private registry and the local image registry?

I have something on my mind that is bugging me. When running docker images I see a list of my local images I have in my docker environment. When pulling Images I pull it from a registry and more specific pull the specified tag managed by the repository.
so there is the registry as the big hub to store all image
repositories
and the repository is storing commits/tagged versions of a specific image
But what is docker images then? It's a registry as well isn't it? It holds all images that I've built locally or pulled.
If my claim is valid:
How does it comply with running a private registry (mentioned here https://docs.docker.com/registry/deploying/)
Running this docker run -d -p 5000:5000 --restart=always --name registry registry:2
Would deploy this new registry into my docker images...
So now I have a registry within my registry... registception?
What is the difference besides the custom registry is deployable?
Its not a local image registry as other questions have pointed. It is an image cache. The purpose of the image cache is to avoid having every time to download the same image whenever you do a docker run.
docker images simply lists all the cached images on the machine. Whenever there is newer image on the registry, the image(some layers) are downloaded and cached when doing docker pull .... Also, when a layer exists in the local cache, docker tells you that, example:
Step 2/2 : CMD /bin/bash
---> Using cache
On the other hand, a docker registry is a central repository to store images. It provide a remote api to pull and push images. The local image cache does not have this feature. Images in the local cache are read and stored used local docker commands that simply read files under /var/lib/docker/...
To make things clear, think of Docker remote registries (such as Docker Hub) as the remote Git repositories. You pull Docker images (like git repositories) that you need and you play with it.
Like remote Git repositories such as GitHub\BitBucket, Docker registries are also public and private. Public registries are for public usage and open-source projects. Examples include in like Docker Hub. Where as private registries are for organizational use or for your own. Examples for private registries include Azure Container Registry, EC2 Container Registry etc.
The official Docker Registry image is just a Docker registry image for your own system, you can't share them with others unless you have a server or a public Internet IP address. Think of it as Bonobo Private Git Server for Windows.
Your local image registry as you mentioned are all those images that you have build locally or pulled from a registry public or private you can see it like a local cache of images that you can re use without download or rebuild each time.
Running the registry what actually does is to spin up a server that implements the Docker Registry API which allows users to push, pull, delete and handles the storage of this images and their layers. See it like a central repository like npm, nexus
For example if you run the registry in your.registry.com:5000
You can do things like
docker build -t your.registry.com:5000/my-image:tag .
docker push your.registry.com:5000/my-image:tag
So others that have access to your server can pull it
docker pull your.registry.com:5000/my-image:tag

Docker show current registry

In docker, how can one display the current registry info you are currently logged in? I installed docker, if I now do docker push, where does it send my images?
I spend over 30min searching this info from Google and docker docs, and couldn't find it, so I think it deserves its own question.
There's no concept of a "current" registry - full image tags always contain the registry address, but if no registry is specified then the Docker Hub is used as the default.
So docker push user/app pushes to Docker Hub. If you want to push it to a local registry you need to explicitly tag it with the registry address:
docker tag user/app localhost:5000/user/app
docker push localhost:5000/user/app
If your local registry is secured, you need to run docker login localhost:5000 but that does not change the default registry. If you push or pull images without a registry address in the tag, Docker will always use the Hub.
This issue explains the rationale.
The way docker images work is not the most obvious but it is easy to explain.
The location where your images will be sent to must be define in the image name.
When you commit an image you must name it [registry-IP]:[registry-port]/[imagepath]/[image-name]
If you already have the image created and you want to send it to the local registry you must tagged it including the registry path before you push it:
docker tag [image-name] [registry-IP]:[registry-port]/[image-name]
docker push [registry-IP]:[registry-port]/[image-name]

Add remote tag to a docker image

On a private registry (myregistry.com), say I have an image tagged with 'v1.2.3'. I then push it by:
docker push myregistry.com/myimage:v1.2.3
If I want to associate another tag, say 'staging', and push that tag to my registry, I can:
docker tag myregistry.com/myimage:v1.2.3 myregistry.com/myimage:staging
docker push myregistry.com/myimage:staging
Though this works, the second docker push still runs through each image, attempting to push it (albeit skipping upload). Is there a better way just to add a remote tag?
The way you've stated, docker tag ...; docker push ... is the best way to add a tag to an image and share it.
In the specific example you've given, both tags were in the same repo (myregistry.com/myimage). In this case you can just docker push myregistry.com/myimage and by default the docker daemon will push all the tags for the repo at the same time, saving the iteration over layers for shared layers.
You can use the same process (docker tag ...; docker push ...) to tag images between repositories as well, e.g.
docker tag myregistry.com/myimage:v1.2.3 otherregistry.com/theirimage:v2
docker push otherregistry.com/theirimage
You can achieve this with docker buildx imagetools create
docker buildx imagetools create myregistry.com/myimage:v1.2.3 --tag myregistry.com/myimage:staging
this will simply download the image manifest of myregistry.com/myimage:v1.2.3 and re-tag (and push) it as myregistry.com/myimage:staging
NOTE: this will also retain the multi-platform manifest list when you "re-tag" (e.g. when your image is build for both linux/arm64 and linux/amd64). Where as the conventional docker pull/push strategy will only retain the image manifest for the platform/architecture of the system you do the pull/push from.
pull/tag/push method will have time&network costs, you can just remotely tag your image with:
only for changing TAG the answer https://stackoverflow.com/a/38362476/8430173 works , but I wanted to change the repository name too.
by many thanks to this, I changed the repoName too!
(by help of his Github project):
1- get manifests (in v2 schema)
2- post every layer.digest in the new repo
3- post config.layer
4- put whole manifest to new repo
details:
1- GET manifest from reg:5000/v2/{oldRepo}/manifests/{oldtag} withaccept header:application/vnd.docker.distribution.manifest.v2+json
2- for every layer : POST reg:5000/v2/{newRepo}/blobs/uploads/?mount={layer.digest}&from={oldRepoNameWithaoutTag}
3- POST reg:5000/v2/{newRepo}/blobs/uploads/?mount={config.digest}&from={oldRepoNameWithaoutTag}
4- PUT reg:5000/v2/{newRepo}/manifests/{newTag} with content-type header:application/vnd.docker.distribution.manifest.v2+json and body from step 1 response
5- enjoy!
For single platform images, you can use
docker pull repo:oldtag
docker tag repo:oldtag repo:newtag
docker push repo:newtag
However, there are a few downsides.
You pull all the layers even if you don't need to run the image locally.
You are dereferencing multi-platform images to your local platform.
This can be done with curl, especially if you are in the same repository (when you go across repositories, you also need to copy all the blobs). However, that has two challenges of its own:
You need to accept all of the possible media types for the image you are pulling, track the media type you received, and use that same media type when pushing the manifest back to the registry. There are at least 6 media types I'm familiar with:
a signed and unsigned docker schema v1
the common manifest and manifest list in docker schema v2
the OCI image and index
If you go across repositories, you need to parse the manifest for the included blobs, which can be recursive for docker manifest lists and OCI indexes. You may be able to do a server side blob mount to avoid pulling and pushing the blob, but that will depend on the server support. And we're also going to see anonymous blob mounts come to registries, which allows a blob mount even if you don't know the source repo on that registry (useful for everyone pushing to a cloud registry with an image based on an official docker image from Docker Hub).
Authorization gets complicated, particularly if you have bearer tokens to request and maintain between commands.
The solution I'd recommend is using a tool that handles the registry API for you. I've been working on my own tooling for this, regclient, and there are other similar projects like Google's crane and RedHat's skopeo. These should each handle the media types, copying blobs when needed, and authorization issues that would complicate the curl command.
As an example with regclient's regctl command, you'd run:
regctl image copy repo:oldtag repo:newtag
With google's crane you just do
crane tag myregistry.com/myimage:v1.2.3 staging
It works with both docker images and OCI images, no image is downloaded locally and it even skips the layer verifications, as they are guaranteed to already be in the repository.
It's even available in a docker image: gcr.io/go-containerregistry/crane
Note that there are other similar tools, like regctl or skopeo
There is a simpler method with the new experimental manifest Docker commands. It only requires downloading and uploading the manifest file (JSON overview) of an image. The commands below have been tested with the GitLab registry. First build and push a Docker image in some previous stage:
docker build -t registry.gitlab.com/<group>/<project>/<image-name>:<tag-a> .
docker push registry.gitlab.com/<group>/<project>/<image-name>:<tag-a>
Then at a later stage where the image has not been pulled:
docker manifest create registry.gitlab.com/<group>/<project>/<image-name>:<tag-b> \
registry.gitlab.com/<group>/<project>/<image-name>:<tag-a>
docker manifest push registry.gitlab.com/<group>/<project>/<image-name>:<tag-b>
You can then pull the image with the new tag. The first step did not seem to work with public Docker Hub images, but any suggestions are welcome. Additionally, to see the manifest itself, run:
docker manifest inspect registry.gitlab.com/<group>/<project>/<image-name>:<tag-a>

Resources