• 8 hours
  • Medium

Free online content available in this course.

course.header.alt.is_certifying

Got it!

Last updated on 8/28/24

Use Images With Sharing on Docker Hub

Now that you’ve created your own image using a Dockerfile, you want to share this image with your colleagues. To do this, you have two options:

  • Either you share your Dockerfile with each of your colleagues in turn, and you ask them to create their own image with a  docker build.

  • Or, you send your image on your own registry.

The first option will work perfectly well, but will mean your colleagues have to recreate each of the images themselves, and that can be pretty time-consuming.

You can get around this by using a Docker registry, through which you can share your image directly.

Create Your Image on Docker Hub

You’re going to create your Docker image on Docker Hub to make it publicly accessible to your whole community.

To get started, head to https://hub.docker.com/ and log in with the account you created when installing Docker.

Next, click on Create a Repository. This will take you to a page where you type in your image name along with a description.

For the remainder of this course, we’ll call this image  ocr-docker-build. You can use the same name for your repository in Docker Hub.

Send Your Image on Docker Hub

Last chapter, you created a Docker image using the docker buildcommand. We’re now going to publish this image on Docker Hub. We’ll need to use a few different commands to do this.

Here’s the first one:  docker tag ocr-docker-build:latest YOUR_USERNAME/ocr-docker-build:latest. This will create a link between the image we’ve created (  ocr-docker-build:latest  ) and the image that we want to send to Docker Hub (  YOUR_USERNAME/ocr-docker-build:latest  ).

➜ docker tag ocr-docker-build:latest ocr/ocr-docker-build:latest
➜ docker tag id_of_container openclassrooms/ocr-docker-build:latest

You can now execute the final command required to send your image to Docker Hub:  docker push YOUR_USERNAME/ocr-docker-build:latest.

➜ docker push ocr/ocr-docker-build:latest
The push refers to repository [docker.io/ocr/ocr-docker-build]
00f821099106: Pushed
e9223d0e868c: Pushed
3d99cd871f5d: Pushed
fbb641a8b943: Mounted from library/debian
latest: digest: sha256:a24595e38d46841b4b571cde8bd65d49638bec2dbfc08b8bfa5fc47995a0972e size: 1165

If you now go back to the Docker Hub page for your image, you’ll see that there’s an initial version of it.

You can create other versions of your image, replacing  :latest  with another string. Watch out, though, the default image used will always be the  :latest  image.

Find the Image You Want

You may need to search for images in Docker Hub, so you should be aware that there are two different types of images:

  • Official images

  • Personal images

To date, Docker has over 150 official images that it keeps continuously updated, which you can find here on Docker Hub.

There are also lots of personal images created by different members of the community, some of which are even created by editors of open source solutions.

There are two ways to search for an image:

  • The command-line option

  • The web interface option

For option one, you’ll need to use the  docker search  command. So, if we’re searching for an Nginx image, it would be:

docker search nginx
NAME DESCRIPTION STARS OFFICIAL AUTOMATED
nginx Official build of Nginx. 11115 [OK]
jwilder/nginx-proxy Automated Nginx reverse proxy for docker con… 1569 [OK]
richarvey/nginx-php-fpm Container running Nginx + PHP-FPM capable of… 695 [OK]
jrcs/letsencrypt-nginx-proxy-companion LetsEncrypt container to use with nginx as p… 494 [OK]
webdevops/php-nginx Nginx with PHP-FPM 123 [OK]
kitematic/hello-world-nginx A light-weight nginx container that demonstr… 123
zabbix/zabbix-web-nginx-mysql Zabbix frontend based on Nginx web-server wi… 92 [OK]
bitnami/nginx Bitnami nginx Docker Image 64 [OK]
linuxserver/nginx An Nginx container, brought to you by LinuxS… 56
1and1internet/ubuntu-16-nginx-php-phpmyadmin-mysql-5 ubuntu-16-nginx-php-phpmyadmin-mysql-5 49 [OK]
tobi312/rpi-nginx NGINX on Raspberry Pi / armhf 24 [OK]
nginx/nginx-ingress NGINX Ingress Controller for Kubernetes 17
nginxdemos/hello NGINX webserver that serves a simple page co… 13 [OK]
wodby/drupal-nginx Nginx for Drupal container image 12 [OK]
blacklabelops/nginx Dockerized Nginx Reverse Proxy Server. 12 [OK]
schmunk42/nginx-redirect A very simple container to redirect HTTP tra… 11 [OK]
centos/nginx-18-centos7 Platform for running nginx 1.8 or building n… 10
centos/nginx-112-centos7 Platform for running nginx 1.12 or building … 7
nginxinc/nginx-unprivileged Unprivileged NGINX Dockerfiles 4
1science/nginx Nginx Docker images that include Consul Temp… 4 [OK]
mailu/nginx Mailu nginx frontend 3 [OK]
travix/nginx NGinx reverse proxy 2 [OK]
toccoag/openshift-nginx Nginx reverse proxy for Nice running on same… 1 [OK]
ansibleplaybookbundle/nginx-apb An APB to deploy NGINX 0 [OK]
wodby/nginx

As you can see, the Docker CLI returns a list of available Docker images.

You can carry out the same action via Docker Hub. If we’re searching for an image there, here’s the search URL. Here again, we’ll find a list of images along with the filters required to sort the images in the way you want to.

Let’s Recap!

You now know how to send your image to Docker Hub, and you also know how to search the Hub for images.

Remember these key commands:

  • docker push  for sending your local images to a directory

  • docker search  for searching for an image in your directory

In the next part, we’ll learn how to use Docker Compose to manage your containers.

Example of certificate of achievement
Example of certificate of achievement