2020-10-28 05:18:34 +00:00
# # Pull Docker Images
2014-09-26 07:44:31 +00:00
2020-10-28 05:18:34 +00:00
As we have mentioned , there are many high quality docker images on [ Docker Hub ] ( https : //hub.docker.com/explore/). In this section, we will introduce how to `pull` these images.
2014-09-26 07:44:31 +00:00
2020-10-28 05:18:34 +00:00
The command to fetch image from docker registry is ` docker pull ` . The command format is :
2016-11-11 06:22:30 +00:00
` ` ` bash
2020-10-28 05:18:34 +00:00
docker pull [ OPTIONS ] [ Docker Registry ADDRESS [ : PORT ] / ] NAME [ : TAG ]
2014-09-26 07:44:31 +00:00
` ` `
2014-10-14 05:25:01 +00:00
2020-10-28 05:18:34 +00:00
More options can be found by ` docker pull --help ` command . Now let us see the format for image names .
2014-09-26 07:44:31 +00:00
2020-10-28 05:18:34 +00:00
* Docker Repository Address : the address format is typically ` <domain/IP>[:PORT] ` . The default address is Docker Hub .
2014-09-26 07:44:31 +00:00
2020-10-28 05:18:34 +00:00
* Repository : as mentioned before , the repository name consists of 2 parts , i . e . , ` username/software-name ` ( separated by the slash ) . For docker Hub , if the username is not specified , the default is ` library ` , where all the official images are in .
For example ,
2016-11-11 06:22:30 +00:00
` ` ` bash
2018-12-08 13:47:05 +00:00
$ docker pull ubuntu : 18.04
18.04 : Pulling from library / ubuntu
2016-11-11 06:22:30 +00:00
bf5d46315322 : Pull complete
9 f13e0ac480c : Pull complete
e8988b5b3097 : Pull complete
40 af181810e7 : Pull complete
e6f7c7e5c03e : Pull complete
Digest : sha256 : 147913621 d9cdea08853f6ba9116c2e27a3ceffecf3b492983ae97c3d643fbbe
2018-12-08 13:47:05 +00:00
Status : Downloaded newer image for ubuntu : 18.04
2014-09-26 07:44:31 +00:00
` ` `
2016-11-11 06:22:30 +00:00
2020-10-28 05:18:34 +00:00
The Docker image repository is not given , so it will pull the image from Docker Hub . Since the image name is ` ubuntu:18.04 ` , so it will get the official image with tag ` 18.04 ` from ` library/ubuntu ` .
2016-11-11 06:22:30 +00:00
2020-10-28 05:18:34 +00:00
From the download log , we can see the layered storage concept - images are composed of multiple layers of storage . And we download images layer by layer instead of a single file . During the download process , the first 12 hexadecimal bits of each layer are shown . And after the download , the ` sha256 ` summary is given , to verify the integrity of downloaded files .
2016-11-11 06:22:30 +00:00
2020-10-28 05:18:34 +00:00
When using the above command , you may find that the layer ID and ` sha256 ` you see are different from what they are here , because the official layer is maintained and updated frequently . In case there is any new bug or new edition , the image will be rebuilt and published with the original tag . This makes sure that all the users use safer and more stable images .
2016-11-11 06:22:30 +00:00
2020-10-28 05:18:34 +00:00
* If it is slow to download images from Docker Hub , you can refer to [ Image Accelerators ] ( / install / mirror . md ) to configure accelerator . *
2016-11-11 06:22:30 +00:00
2020-10-28 05:18:34 +00:00
# # # Run
With the image , we can run a container based on the image . Taking the above ` ubuntu:18.04 ` as an example , if we want to start the ` bash ` inside it for interactive operations , we can execute the following commands .
2016-11-11 06:22:30 +00:00
` ` ` bash
2017-10-24 04:30:17 +00:00
$ docker run - it -- rm \
2018-12-08 13:47:05 +00:00
ubuntu : 18.04 \
2017-10-24 04:30:17 +00:00
bash
2016-11-11 06:22:30 +00:00
root @ e7009c6ce357 : / # cat / etc / os - release
NAME = "Ubuntu"
2018-12-08 13:47:05 +00:00
VERSION = "18.04.1 LTS (Bionic Beaver)"
2016-11-11 06:22:30 +00:00
ID = ubuntu
ID_LIKE = debian
2018-12-08 13:47:05 +00:00
PRETTY_NAME = "Ubuntu 18.04.1 LTS"
VERSION_ID = "18.04"
HOME_URL = "https://www.ubuntu.com/"
SUPPORT_URL = "https://help.ubuntu.com/"
BUG_REPORT_URL = "https://bugs.launchpad.net/ubuntu/"
PRIVACY_POLICY_URL = "https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"
VERSION_CODENAME = bionic
UBUNTU_CODENAME = bionic
2014-09-26 07:44:31 +00:00
` ` `
2016-11-11 06:22:30 +00:00
2020-10-28 05:18:34 +00:00
` docker run ` is the command for running the container , the detailed format will be explained in the [ container ] ( . . / container ) chapter . Here we only illustrate the parameters used above .
* ` -it ` : There are 2 parameters here , the first is ` -i ` , for interactive operations , another is ` -t ` , which is for terminal . What we intend to do is to enter the ` bash ` terminal of docker , then execute some commands and see the output . That ' s why we need the interactive terminal .
* ` --rm ` : Remove the docker after stop it . In default , for troubleshooting , the docker is not removed immediately after quitting , unless manually remove it using ` docker rm ` . But in our case , we only test the commands and to see the resutls , we don ' t care much about the results , so we use ` --rm ` to avoid wasting space .
* ` ubuntu:18.04 ` : use ` ubuntu:18:04 ` as the base image to start the container .
2016-11-11 06:22:30 +00:00
2020-10-28 05:18:34 +00:00
* ` bash ` : What we have after the image name is * * command * * , since we want an interactive shell , so we use ` bash ` as the command here .
2016-11-11 06:22:30 +00:00
2020-10-28 05:18:34 +00:00
After entering the comainer , we can execute any command we want . Here , we executed ` cat etc/os-release ` , which is the commonly - used command to view the version of the current OS . We can see from the result that the container is based on ` Ubuntu 18.04.1 LTS ` .
2016-11-11 06:22:30 +00:00
2020-10-28 05:18:34 +00:00
In the end , we quit the container with ` exit ` .