Docker show current registry - docker

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]

Related

Docker: get list of all the registries configured on a host

Can docker be connected to more than one registry at a time and how to figure out which registries it is currently connected too?
$ docker help | fgrep registr
login Log in to a Docker registry
logout Log out from a Docker registry
pull Pull an image or a repository from a registry
push Push an image or a repository to a registry
As you can see, there is no option to list the registries. I did find
a way by running:
$ docker system info | fgrep -i registr
Registry: https://index.docker.io/v1/
So... one regsitry at a time only? It is not like apt where one can point to more than one source? Anybody can point me to some good documentation about docker and registries?
Oddly, I search the web to no vail.
Aside from docker login, Docker isn't "connected to a registry" per se. Registry names are part of the image name, and Docker will connect to a registry server if it needs to pull an image.
As a specific example, the official Docker image for Elasticsearch is on a non-default registry run by Elastic. The example in that documentation is
docker pull docker.elastic.co/elasticsearch/elasticsearch:7.17.0
# ^^^^^^^^^^^^^^^^^
# registry host name
You don't need to otherwise configure your system to connect to that registry, download an index, or anything else. In fact, you don't even need this docker pull command; if you directly docker run the image, Docker will download it if it doesn't have a copy locally.
The default registry is Docker Hub, docker.io, and this cannot be changed.
There are several alternate registries out there. The various public-cloud providers each have their own, and there are also several free-standing image registries. Each has its own instructions on how to set it up. You always need to include the registry name as part of the image name. The Google Container Registry has a simple name syntax, for example, so if you use GCR then you can
# build an image locally, labeled to be stored in GCR
# (this step does not contact or use GCR at all)
docker build gcr.io/my-name/my-image:tag
# authenticate to the registry
# (normally GCR has a Google-specific login sequence)
docker login https://gcr.io
# push the image
docker push gcr.io/my-name/my-image:tag
# run the image, pulling it if not present
docker run ... gcr.io/my-name/my-image:tag

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 registry mirror

I'm trying to set a docker mirror to be the default mirror to pull/push images.
As per documentation I already set the file /etc/docker/daemon.json with the following:
{
"registry-mirrors": ["https://localregistry"]
}
Then I try the following:
docker login localregistry
docker pull localregistry/image:tag > it works
docker pull image:tag > doesn't work
I'm always getting "no basic auth credentials error" from the docker daemon, but from the registry log I get err.code="manifest unknown" err.detail="unknown tag"
Any idea?
I'm using docker version 19.03.08
docker login localregistry
First, I hope this is changing the name for the question, because the registry name localregistry will not work...
docker pull localregistry/image:tag > it works
The fact that this works indicates that you likely have a registry name with a . or : in the hostname. Otherwise docker would try to pull localregistry/image:tag from the localregistry user on Docker Hub.
docker pull image:tag > doesn't work
This should always work, failures should be transparent to the user if it's really a mirror of Docker Hub. What happens is it resolves that name to docker.io/library/image:tag, first tries to pull from localregistry/library/image:tag, and any error falls back to a pull from Docker Hub, and any error there finally shows to the user.
Most likely the issue is that you didn't include library as the repo name for your image in the local registry.
If you are using this to include images that don't exist on Docker Hub, then I would skip the mirror and simply refer to the mirror explicitly. Doing otherwise creates many opportunities for nonintuitive failures that aren't easy to see. E.g. a stale image can be pushed to your mirror in place of an upstream image, and Docker will stop pulling updates from upstream. And because any mirror errors fall back to Hub, if you use an image name that you have no control over upstream, someone else could take that name on Hub and begin injecting unknown or even malicious images into your server.
If this doesn't answer your question, then I'd recommend using your question with actual image names and error messages from the logs showing what specifically failed (you can mask out part of the registry name of necessary).

Docker: Push data container onto Docker Hub

I am really new at this Docker stuff, and even newer at Docker Hub, so please bear with me …
I have created a data container to use with my docker image (specifically, a data container to store data for a running mssql-server-lnux image). I know where it is on my local system.
I have a newly created account on Docker Hub and I think I want to push the data container on the hub. I say I think because I’m not sure that it’s the right way to go about it: I want to be able to use the data container from different machines.
If what I have said so far is in the right direction, then how do I push the docker image to the Hub, and how do I then access it later?
You can't push containers, only images, the distinction is important.
Image is akin to a class of your container, and container is essentially an instance of your image.
So if you want to push to share your database then it's not a good idea - you would have to docker commit first and this would get ugly really fast.
But if you just want to start new instances of your mysql on different machines with fresh data containers (there will be no data initially) then go ahead and push the data container image.
Hope this helps.
Okay, here are few steps. Please check if this helps.
Tag your image first. Let's say your image name is 'myapplication' and your docker hub user name is 'dockerhubusername'.
$ docker tag myapplication dockerhubusername/myapplication
Login to docker hub using. Enter user name like 'dockerhubusername' and then password of docker hub account.
$ docker login
Now push command.
$ docker push dockerhubusername/myapplication
Now, login to your docker hub and check if you have image there. Remember, images are pushed to registry/repository like dockerhub not containers.
Assuming you have tagged your image,
Use docker login to configure your docker hub credentials and use docker push to push your image to dockerhub.
$ docker login
$ docker push dockerhub_username/mssql-server-lnux
If you have not yet tagged the image,
$ docker tag mssql-server-lnux dockerhub_username/mssql-server-lnux
To access your image later,
$ docker pull dockerhub_username/mssql-server-lnux
References
Docker Pull
Docker Login

Difference between Docker registry and repository

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...

Resources