Docker

How to Use Docker Registry?

Today, we’ll discuss the Docker Registry and how to use it.

What is Docker?

As you all probably know, Docker enables us to come up with virtual machines that succinctly encase applications, programs, and their dependencies into a container. This is different from a hypervisor in the sense that it containerizes applications through virtualizations, whereas a hypervisor emulates an operating system and its contents. Docker alleviates the process of distributing apps by containerizing them via docker registries.

Installing Docker on Ubuntu: Quick Overview

We’ll gloss over the detail in this section, but if you’re used to installing such software, you’ll do just fine with the instructions here. We’ll cover the default method to setting up Docker; via  the official docker repository:

Issue the command below to get the administrator rights:

$ sudo apt update

Then use curl to add docker repository key with the command below:

$ sudo apt install apt-transport-https ca-certificates curl software-properties-common

Then add the repository path that leads to wherever package files are located:

$ curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -

$ sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu focal stable"

Update apt repository:

$ sudo apt update

Then install docker:

$ apt-cache policy docker-ce

$ sudo apt install docker-ce

$ sudo systemctl status docker

Using Docker Registry

Before we get into the details, let’s cover the basics first.

The two types of docker registries are private and public.

Registries such as Quay, Docker Hub, Google Container, and AWS Container are all private.

Docker Hub registry, on the other hand, is a community-based host– a public registry of sorts.

These registries host images and allow users to upload or download them. In the next section, we’ll see exactly how it’s done

Accessing Docker Registries

We’ll use the public registry that docker gives you to use when you sign up. You don’t need to register an account to transferring images to disk, however, you’ll need to upload them.

To register a user account, go to the official docker website: https://hub.docker.com/

Enter your user credentials  and create an account; then come back here and click the link given: https://hub.docker.com/explore/

Select an image. For the purpose of demonstration, we’ll download the PHP one and recommend you do the same to follow along. You’ll find the PHP image here: https://hub.docker.com/_/php/

Make sure you have root privileges, then type in the command below:

$ docker pull php

Upon the execution of the command above, the PHP image will write to your disk.

Access the docker file with the command below:

$ nano docker file

Then enter these commands to fetch the php 7 contents, so when the container is running, the dependencies are searched from here.

$ FROM php:7.0-cli

In order to copy the files from the source to the directory, type the following:

$ COPY . /usr/src/myapp

Now use the given command to get the workdir to name the working directory as path:

$WORKDIR /usr/src/myapp

Then specify for the command to run later:

$ CMD [ "php", "./donscript.php" ]

Now that we’ve created the dockerfile, we’ll need to compile it to create a docker image.

$ docker build -t donapp

In case the php script requests access to a web browser to display the features, you can issue the following command to enable the default web host:

$ docker run php -S localhost:8000

The directory of both dockerfile and the script has to be the same. Make sure to accurately name the script as named before in the CMD command.

Our docker image is ready to go:

$ docker run donapp

If for some reason you can’t do the compiling, you can use the command below, complete with the script name:

docker run -it --rm --name my-running-script -v "$PWD":/usr/src/myapp -w /usr/src/myapp php:7.0-cli php donscript.php

Looking for Images in Docker Registries

You can look up images via terminal without even opening your browser. Just type in the command below with an image that exists in your HDD:

$ docker search <image name>

example: docker search ubuntu

Uploading Images to Registry

If you’re uploading for personal usage or within a group of people like coworkers, you should upload to a private registry. If it’s something you want to share publicly, then you should obviously go with the public registry option.

Log into your docker hub account and access the registry with the command below, with the username:

$ docker login –username MYUSERNAME

Then give in the password when prompted:

Use the format below to tag the program.

$ docker tag donapp dondilanga/donapp

Now upload the image with the command below:

$ docker push dondilanga/donapp

Wrapping Up

This tutorial covered the basics of using docker and its registries. We also discussed how you could install it via the official docker repositories. Furthermore, we looked into how docker files are created, and images are executed.

About the author

Younis Said

I am a freelancing software project developer, a software engineering graduate and a content writer. I love working with Linux and open-source software.