Introducing Docker Hub
You will typically interact with Docker Hub from the command line or in Dockerfiles, but you can use the Docker Hub website (https://hub.docker.com) to search for any pre-built containers that you know you want to use. You can also use the website to discover pre-built containers that might be of interest to you.
In general, you will inherit from some pre-built Docker containers on Docker Hub to create your own custom containers. For example, you might inherit from a Linux distribution container and install the software you want for your project within that inherited/custom container.
When you inherit from the Linux distribution, some of that distribution's base software packages are installed. If you inherit from a Debian-flavor Linux container, you will be able to use the apt package manager within the container to install software as if you were running that Debian-flavor Linux container on a dedicated or virtual machine.
Some pre-built containers inherit from a Linux flavor and provide pre-installed packages that are specific to the offering. When you inherit from a Node.js container, that Node.js container might inherit from a Linux distribution container and will have Node.js, npm, and yarn already installed.
Interacting with Docker Hub from the command line
The easiest way to see Docker Hub and Docker working together is to run the official hello-world container. The command to run a container from Docker Hub is docker run name-of-container; we'll type docker run hello-world:
# docker run hello-world Unable to find image 'hello-world:latest' locally latest: Pulling from library/hello-world 1b930d010525: Pull complete Digest: sha256:4fe721ccc2e8dc7362278a29dc660d833570ec2682f4e 4194f4ee23e415e1064 Status: Downloaded newer image for hello-world:latest
Hello from Docker!
This message shows that your installation appears to be working correctly.
To generate this message, Docker took the following steps: 1. The Docker client contacted the Docker daemon. 2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
(amd64)
3. The Docker daemon created a new container from that image which runs the
executable that produces the output you are currently reading.
4. The Docker daemon streamed that output to the Docker client, which sent it
to your terminal.
To try something more ambitious, you can run an Ubuntu container with:
$ docker run -it ubuntu bash
Share images, automate workflows, and more with a free Docker ID:
For more examples and ideas, visit:
https://docs.docker.com/get-started/
Docker did not find the container in its local container cache, so it automatically downloaded it and then ran it within the Docker engine. This code in the container is simple—it just prints the preceding messages.
Note
You can run any container you find on the Docker Hub website in the same way!
If your output does not resemble the preceding output, you either have an issue with your Docker installation or the Docker Hub servers are not accessible from your host. One possible problem may be that your installation of Docker requires you to run the docker commands as root or an administrator.
The installation instructions can be found at https://docs.docker.com/install/, while the post-installation instructions for Docker can be found at https://docs.docker.com/install/linux/linux-postinstall/. These post-installation instructions explain how to set up Docker so that you can manage it as a non-root user.
Using the Docker Hub website
Let's go find the hello-world container page in Docker Hub—https://hub.docker.com/_/hello-world. The page will look something like this:
This is typical of what you'll see for most containers shared on Docker Hub. Specific software packages encapsulated in a container, such as MongoDB, offer official images for various versions of the software. This allows you to deal with software that depends on a specific version of a Docker Hub package.
The MongoDB page on Docker Hub is https://hub.docker.com/_/mongo. To find it, simply type mongodb into the search box at the top of the hello-world (or any other package) page and select it from the search results page. You can use the search box to find any shared images for whatever software you might want.
Of interest are the Simple Tags and Shared Tags sections of the page. The various version images of MongoDB are tagged with simple tags and shared tags.
For example, the 3.4-xenial simple tag means there is an image for version 3.4 of MongoDB running in an Ubuntu Xenial container.
The 3.4 shared tag means there are images of version 3.4 of MongoDB that run on more than one host operating system—typically, Windows Server, Linux, or macOS. The Docker daemon will choose the appropriate image for the host operating system.
As of the time of writing, there are images for the MongoDB 3.4, 3.6, 4.0, and 4.2 major versions, as well as minor point versions of these major versions:
The process for finding the available pre-built third-party containers is the same. You can search for Redis, for example, and you will get a similar page with details about the available Redis containers.