本文共 3311 字,大约阅读时间需要 11 分钟。
Docker images are the basis of containers. Each time you’ve used docker run
you told it which image you wanted. In the previous sections of the guide youused Docker images that already exist, for example the ubuntu
image and thetraining/webapp
image.
You also discovered that Docker stores downloaded images on the Docker host. Ifan image isn’t already present on the host then it’ll be downloaded from aregistry: by default the .
In this section you’re going to explore Docker images a bit moreincluding:
Let’s start with listing the images you have locally on our host. You cando this using the docker images
command like so:
$ docker imagesREPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZEubuntu 14.04 1d073211c498 3 days ago 187.9 MBbusybox latest 2c5ac3f849df 5 days ago 1.113 MBtraining/webapp latest 54bb4e8718e8 5 months ago 348.7 MB
You can see the images you’ve previously used in the user guide.Each has been downloaded from when youlaunched a container using that image. When you list images, you get three crucial pieces of information in the listing.
ubuntu
.14.04
.Tip:You can use or the to display
visualizations of image data.
A repository potentially holds multiple variants of an image. In the case ofour ubuntu
image you can see multiple variants covering Ubuntu 10.04, 12.04,12.10, 13.04, 13.10 and 14.04. Each variant is identified by a tag and you canrefer to a tagged image like so:
ubuntu:14.04
So when you run a container you refer to a tagged image like so:
$ docker run -t -i ubuntu:14.04 /bin/bash
If instead you wanted to run an Ubuntu 12.04 image you’d use:
$ docker run -t -i ubuntu:12.04 /bin/bash
If you don’t specify a variant, for example you just use ubuntu
, then Dockerwill default to using the ubuntu:latest
image.
Tip:You recommend you always use a specific tagged image, for example
ubuntu:12.04
. That way you always know exactly what variant of an image isbeing used.
So how do you get new images? Well Docker will automatically download any imageyou use that isn’t already present on the Docker host. But this can potentiallyadd some time to the launch of a container. If you want to pre-load an image youcan download it using the docker pull
command. Suppose you’d like todownload the centos
image.
$ docker pull centosPulling repository centosb7de3133ff98: Pulling dependent layers5cc9e91966f7: Pulling fs layer511136ea3c5a: Download completeef52fb1fe610: Download complete. . .Status: Downloaded newer image for centos
You can see that each layer of the image has been pulled down and now youcan run a container from this image and you won’t have to wait todownload the image.
$ docker run -t -i centos /bin/bashbash-4.1#
One of the features of Docker is that a lot of people have created Dockerimages for a variety of purposes. Many of these have been uploaded to. You can search these images on the website.
转载地址:http://bnhbi.baihongyu.com/