Docker containers are run from Docker images. By default, it pulls these images from Docker Hub, a Docker registry managed by Docker, the company behind the Docker project. Anybody can build and host their Docker images on Docker Hub, so most applications and Linux distributions you’ll need to run Docker containers have images that are hosted on Docker Hub.
To check whether you can access and download images from Docker Hub, type:
docker run hello-world
In the output, you should see the following message, which indicates that Docker is working correctly:
Output... Hello from Docker! This message shows that your installation appears to be working correctly. ...
You can search for images available on Docker Hub by using the
docker command with the
search subcommand. For example, to search for the Ubuntu image, type:
docker search ubuntu
The script will crawl Docker Hub and return a listing of all images whose name matches the search string. In this case, the output will be similar to this:
Output NAME DESCRIPTION STARS OFFICIAL AUTOMATED ubuntu Ubuntu is a Debian-based Linux operating sys… 8564 [OK] dorowu/ubuntu-desktop-lxde-vnc Ubuntu with openssh-server and NoVNC 230 [OK] rastasheep/ubuntu-sshd Dockerized SSH service, built on top of offi… 176 [OK] consol/ubuntu-xfce-vnc Ubuntu container with "headless" VNC session… 129 [OK] ansible/ubuntu14.04-ansible Ubuntu 14.04 LTS with ansible 95 [OK] ubuntu-upstart Upstart is an event-based replacement for th… 91 [OK] neurodebian NeuroDebian provides neuroscience research s… 54 [OK] 1and1internet/ubuntu-16-nginx-php-phpmyadmin-mysql-5 ubuntu-16-nginx-php-phpmyadmin-mysql-5 48 [OK] ubuntu-debootstrap debootstrap --variant=minbase --components=m… 39 [OK] nuagebec/ubuntu Simple always updated Ubuntu docker images w… 23 [OK] tutum/ubuntu Simple Ubuntu docker images with SSH access 18 i386/ubuntu Ubuntu is a Debian-based Linux operating sys… 14 1and1internet/ubuntu-16-apache-php-7.0 ubuntu-16-apache-php-7.0 13 [OK] ppc64le/ubuntu Ubuntu is a Debian-based Linux operating sys… 12 eclipse/ubuntu_jdk8 Ubuntu, JDK8, Maven 3, git, curl, nmap, mc, … 6 [OK] 1and1internet/ubuntu-16-nginx-php-5.6-wordpress-4 ubuntu-16-nginx-php-5.6-wordpress-4 6 [OK] codenvy/ubuntu_jdk8 Ubuntu, JDK8, Maven 3, git, curl, nmap, mc, … 4 [OK] darksheer/ubuntu Base Ubuntu Image -- Updated hourly 4 [OK] pivotaldata/ubuntu A quick freshening-up of the base Ubuntu doc… 2 1and1internet/ubuntu-16-sshd ubuntu-16-sshd 1 [OK] smartentry/ubuntu ubuntu with smartentry 1 [OK] ossobv/ubuntu Custom ubuntu image from scratch (based on o… 0 paasmule/bosh-tools-ubuntu Ubuntu based bosh-cli 0 [OK] 1and1internet/ubuntu-16-healthcheck ubuntu-16-healthcheck 0 [OK] pivotaldata/ubuntu-gpdb-dev Ubuntu images for GPDB development 0
In the OFFICIAL column, OK indicates an image built and supported by the company behind the project. Once you’ve identified the image that you would like to use, you can download it to your computer using the
pull subcommand. Try this with the
ubuntu image, like so:
docker pull ubuntu
After an image has been downloaded, you may then run a container using the downloaded image with the
run subcommand. If an image has not been downloaded when
docker is executed with the
run subcommand, the Docker client will first download the image, then run a container using it:
docker run ubuntu
To see the images that have been downloaded to your computer, type:
The output should look similar to the following:
OutputREPOSITORY TAG IMAGE ID CREATED SIZE ubuntu latest ea4c82dcd15a 16 hours ago 85.8MB hello-world latest 4ab4c602aa5e 5 weeks ago 1.84kB
As you’ll see later in this tutorial, images that you use to run containers can be modified and used to generate new images, which may then be uploaded (pushed is the technical term) to Docker Hub or other Docker registries.