Skip to content

Instantly share code, notes, and snippets.

@mkfares
Created July 29, 2020 12:58
Show Gist options
  • Save mkfares/55f7a8edbb29a3d4a6060cd34d8c3378 to your computer and use it in GitHub Desktop.
Save mkfares/55f7a8edbb29a3d4a6060cd34d8c3378 to your computer and use it in GitHub Desktop.
Working with Docker Registries

Working with Registries

Registry: It is server where container images are stored and shared with other users. Registries may be private or public. The default registry is Docker Hub (docker.io).

Repository: It is a grouping of related container images. Usually, it contains an image with multiple versions. A registry may contain multiple repositories.

Tag: It is a version number or a name given to an image. An image name is composed of the name itself and a tag. The name follow the form image_name:tag ( alpine:3.1, alpine:latest). If the tag is not provided, the latest is assumed.

Image namespace: It is the fully qualified name of an image. It include the registry, username / organization, repository, image name, and image tag (myregistry.com/username/linux/fedora:32.0)

Official Repositories: They are repositories maintained by the teams and organizations that are responsible of the software inside the images.

Pull images from registries

Images can be downloaded from a registry to the local system.

$ docker pull <image>:<tag>
$ docker image pull alpine
$ docker pull alpine:3.12

An image can be pulled using its digest.

$ docker pull alpine@sha256:185518070891758909c9f839cf4ca393ee977ac378609f700f60a771a2dfe321

You may specify the full path of the image.

$ docker pull myregistry.com/username/ubuntu:latest

Login to registries

Before uploading images to a docker registry, you need to login with a username and password.

To login to Docker Hub

$ docker login
$ docker login -u <username> -p <password>

To login to a specific registry, provide the domain name of the registry.

$ docker login myregistry.com

Logout from registries

To logout from a registry, you need to provide the address of the registry. The Docker Hub is the default registry when the registry address is omitted.

$ docker logout myregistry.com
$ docker logout

Push images to registries

$ docker push <image>:<tag>
$ docker image push <image>:<tag>

Before pushing an image to Docker Hub, you need to name (tag) it first. The naming can be achieved in different ways.

$ docker build -t <username>/<repo_name>:<tag>
$ docker tag <existing_image> <docker_hub_username>/<repo_name>:<tag>
docker commit <existing-container> <docker_hub_username>/<repo-name>[:<tag>]

The repo_name is the repository name or image name.

If no tag is provided, the latest tag is assumed.

To verify that your image was successfully pushed to the repository, issue the command:

$ docker images

The image <username>/<repo-name>:<tag> should be included in the displayed list.

Search images in registries

To search for an image in the Docker Hub, issue the command:

$ docker search [options] <search-keyword>
$ docker search centos

To limit the search to a certain number of search results (default 25 results):

$ docker search --limit 10 centos

To search for images with certain number of stars

$ docker search --filter stars=4 centos

To search for official images only

$ docker search --filter is-official=true ubuntu
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment