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:
Then use curl to add docker repository key with the command below:
Then add the repository path that leads to wherever package files are located:
Update apt repository:
Then install 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:
Upon the execution of the command above, the PHP image will write to your disk.
Access the docker file with the command below:
Then enter these commands to fetch the php 7 contents, so when the container is running, the dependencies are searched from here.
In order to copy the files from the source to the directory, type the following:
Now use the given command to get the workdir to name the working directory as path:
Then specify for the command to run later:
Now that we’ve created the dockerfile, we’ll need to compile it to create a docker image.
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:
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:
If for some reason you can’t do the compiling, you can use the command below, complete with the script name:
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:
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:
Then give in the password when prompted:
Use the format below to tag the program.
Now upload the image with the command below:
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.