Merge pull request #474 from Bill0412/english

translate image/list.md to English
This commit is contained in:
Kang Huaishuai 2020-11-09 13:12:47 +08:00 committed by GitHub
commit 8888612782
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 29 additions and 29 deletions

View File

@ -1,6 +1,6 @@
## 列出镜像
## List all Images
要想列出已经下载下来的镜像可以使用 `docker image ls` 命令
If you want to list all the images downloaded, you can use the command `docker image ls` or `docker images`.
```bash
$ docker image ls
@ -13,17 +13,17 @@ ubuntu 18.04 f753707788c5 4 weeks ago
ubuntu latest f753707788c5 4 weeks ago 127 MB
```
列表包含了 `仓库名``标签``镜像 ID``创建时间` 以及 `所占用的空间`
You can see `Repository`, `Tag`, `Image ID`, `Created` and `Size` from the list.
其中仓库名标签在之前的基础概念章节已经介绍过了**镜像 ID** 则是镜像的唯一标识一个镜像可以对应多个 **标签**因此在上面的例子中我们可以看到 `ubuntu:18.04` `ubuntu:latest` 拥有相同的 ID因为它们对应的是同一个镜像
Among these, the repository name and tag have been introduced in the basic concepts chapter. **Image ID** is the unique identifier for the image, and an image can correspond to multiple **labels**. In the exmaple above, we can see `ubuntu:18:04` and `ubuntu:latest` having the same ID, since they are aliases for the same image.
### 镜像体积
### Image Size
如果仔细观察会注意到这里标识的所占用空间和在 Docker Hub 上看到的镜像大小不同比如`ubuntu:18.04` 镜像大小在这里是 `127 MB`但是在 [Docker Hub](https://hub.docker.com/r/library/ubuntu/tags/) 显示的却是 `50 MB`。这是因为 Docker Hub 中显示的体积是压缩后的体积。在镜像下载和上传过程中镜像是保持着压缩状态的,因此 Docker Hub 所显示的大小是网络传输中更关心的流量大小。而 `docker image ls` 显示的是镜像下载到本地后,展开的大小,准确说,是展开后的各层所占空间的总和,因为镜像到本地后,查看空间的时候,更关心的是本地磁盘空间占用的大小。
If you pay close attention to all of these. You may find that the disk space they occupy is different from the one at Docker Hub. For example, `ubuntu:18.04` is `127MB` here, but on [Docker Hub](https://hub.docker.com/r/library/ubuntu/tags/), `50MB` is displayed. That's because what is shown on Docker Hub is the size after compression. During image download and upload, the image is compressed, because the data transfer is the main factor taken into consideration. However, when we use the command `docker image ls`, that's the size after expansion. To be more precisely, the total size after expanding all the layers locally, because we care more about local space occupied when an image is on our disk.
另外一个需要注意的问题是`docker image ls` 列表中的镜像体积总和并非是所有镜像实际硬盘消耗由于 Docker 镜像是多层存储结构并且可以继承复用因此不同镜像可能会因为使用相同的基础镜像从而拥有共同的层由于 Docker 使用 Union FS相同的层只需要保存一份即可因此实际镜像硬盘占用空间很可能要比这个列表镜像大小的总和要小的多
One more thing to note is that in the `docker image ls` list, the total size of images is far less than the actual size. Since the Docker imags are stored in multiple layers, and there are inheritance and reuse, there might be different images using the same basic images and sharing some common layers. As we have mentioned, Docker uses Union FS, we only keep one copy for the same layers, so the actual space occupied is far less than the mere sum.
你可以通过以下命令来便捷的查看镜像容器数据卷所占用的空间
You can use the following command to see the space utilized by images, containers, data volumes.
```bash
$ docker system df
@ -35,15 +35,15 @@ Local Volumes 9 0 652.2MB
Build Cache 0B 0B
```
### 虚悬镜像
### Dangling Image
上面的镜像列表中还可以看到一个特殊的镜像这个镜像既没有仓库名也没有标签均为 `<none>`
In the image list above, we can see a special image, the one without repository name nor tag, all being `<none>`:
```bash
<none> <none> 00285df0df87 5 days ago 342 MB
```
这个镜像原本是有镜像名和标签的原来为 `mongo:3.2`随着官方镜像维护发布了新版本后重新 `docker pull mongo:3.2` `mongo:3.2` 这个镜像名被转移到了新下载的镜像身上而旧的镜像上的这个名称则被取消从而成为了 `<none>`除了 `docker pull` 可能导致这种情况`docker build` 也同样可以导致这种现象由于新旧镜像同名旧镜像名称被取消从而出现仓库名标签均为 `<none>` 的镜像这类无标签镜像也被称为 **虚悬镜像(dangling image)** 可以用下面的命令专门显示这类镜像
This image is originally with name and tag(`mongo:3.2`). As the official image being maintained, and the release of new versions, when we execute `docker pull mongo:3.2`, the tag `mongo:3.2` is transferred to the new iamge, and the name on the old image is canceled, end up being `<none>`. Besides, `docker pull`, `docker build` might also cause this phenomemon. Because the new and old image are of the same name, the name of the old image is canceled, thus causing the repository and tag both being `<none>`. These images without tags are also called **dangling images**, we can use the following commands to show them:
```bash
$ docker image ls -f dangling=true
@ -51,27 +51,27 @@ REPOSITORY TAG IMAGE ID CREATED
<none> <none> 00285df0df87 5 days ago 342 MB
```
一般来说虚悬镜像已经失去了存在的价值是可以随意删除的可以用下面的命令删除
Generally speaking, the dangling images are useless, we can remove them with the following commands with ease:
```bash
$ docker image prune
```
### 中间层镜像
### Intermediate Layer Images
为了加速镜像构建重复利用资源Docker 会利用 **中间层镜像**所以在使用一段时间后可能会看到一些依赖的中间层镜像默认的 `docker image ls` 列表中只会显示顶层镜像如果希望显示包括中间层镜像在内的所有镜像的话需要加 `-a` 参数
To accelerate the build of images and improve the resource utilization, Docker uses **Intermediate Layer Images**. So after using Docker for a while, you may see a list of intermediate images as dependencies. The default `docker image ls` only shows the top images, if you want to show all the images including intermediate images, you need to add the `-a` paramter.
```bash
$ docker image ls -a
```
这样会看到很多无标签的镜像与之前的虚悬镜像不同这些无标签的镜像很多都是中间层镜像是其它镜像所依赖的镜像这些无标签镜像不应该删除否则会导致上层镜像因为依赖丢失而出错实际上这些镜像也没必要删除因为之前说过相同的层只会存一遍而这些镜像是别的镜像的依赖因此并不会因为它们被列出来而多存了一份无论如何你也会需要它们只要删除那些依赖它们的镜像后这些依赖的中间层镜像也会被连带删除
You will see a lot of images without tags with this command. Differing from `dangling images`, these untagged images are intermediate layer images, and are what a lot of other images depend on. These untagged images should not be deleted, otherwise, it will cause missing dependencies errors for upstream images. In fact, these images are not necessary to delete, as we have mentioned, the same layers will be only stored once. These images are dependencies for other images, and their existence will not cause any redundancy, you will need them in any way. They will disappear the moment you delete all the images that reference them.
### 列出部分镜像
### List Images Partially
不加任何参数的情况下`docker image ls` 会列出所有顶层镜像但是有时候我们只希望列出部分镜像`docker image ls` 有好几个参数可以帮助做到这个事情
Without any parameter, `docker image ls` lists all the top-level images, but sometimes we only want them partially. `docker image ls` has several parameters to help us achieve this goal.
根据仓库名列出镜像
To list images based on repository name.
```bash
$ docker image ls ubuntu
@ -80,7 +80,7 @@ ubuntu 18.04 f753707788c5 4 weeks ago
ubuntu latest f753707788c5 4 weeks ago 127 MB
```
列出特定的某个镜像也就是说指定仓库名和标签
To list a certain image, specifying repository name and label.
```bash
$ docker image ls ubuntu:18.04
@ -88,7 +88,7 @@ REPOSITORY TAG IMAGE ID CREATED
ubuntu 18.04 f753707788c5 4 weeks ago 127 MB
```
除此以外`docker image ls` 还支持强大的过滤器参数 `--filter`或者简写 `-f`之前我们已经看到了使用过滤器来列出虚悬镜像的用法它还有更多的用法比如我们希望看到在 `mongo:3.2` 之后建立的镜像可以用下面的命令
Besides, `docker image ls` supports the `--filter` parameter, or simply `-f`. As we have seen before, using filter to list dangling image, and it has more usages. For example, if we want to see images with edition after `mongo:3.2`, we can use the following command:
```bash
$ docker image ls -f since=mongo:3.2
@ -97,18 +97,18 @@ redis latest 5f515359c7f8 5 days ago
nginx latest 05a60462f8ba 5 days ago 181 MB
```
想查看某个位置之前的镜像也可以只需要把 `since` 换成 `before` 即可
If we want to see some versions of images before, we can simply replace `since` with `before`.
此外如果镜像构建时定义了 `LABEL`还可以通过 `LABEL` 来过滤
If we have defined the `LABEL` during the image build, we can also filter with the `LABEL` option.
```bash
$ docker image ls -f label=com.example.version=0.1
...
```
### 以特定格式显示
### Show with Specified Format
默认情况下`docker image ls` 会输出一个完整的表格但是我们并非所有时候都会需要这些内容比如刚才删除虚悬镜像的时候我们需要利用 `docker image ls` 把所有的虚悬镜像的 ID 列出来然后才可以交给 `docker image rm` 命令作为参数来删除指定的这些镜像这个时候就用到了 `-q` 参数
By default, `docker image ls` will show a full list, but we do not need it all the time. For example, when we delete dangling images, we use `docker image ls` to list all the IDs of dangling images and then pass them over to `docker image rm` as parameters to remove the specified images. Under this circumstance, we can apply the `-q` option.
```bash
$ docker image ls -q
@ -121,11 +121,11 @@ f753707788c5
1e0c3dd64ccd
```
`--filter` 配合 `-q` 产生出指定范围的 ID 列表然后送给另一个 `docker` 命令作为参数从而针对这组实体成批的进行某种操作的做法在 Docker 命令行使用过程中非常常见不仅仅是镜像将来我们会在各个命令中看到这类搭配以完成很强大的功能因此每次在文档看到过滤器后可以多注意一下它们的用法
`--filter` together with `-q` to generate a ID list in a specified range, and then passing them over to another `docker` command as parameter is a common practice for Docker commands. Not only for images, we will see all this kind of combinations in other kinds of commands, with them, we can achieve great functionalities. So when you see some filters while reading the documents, please pay attention to how they are used in practice.
另外一些时候我们可能只是对表格的结构不满意希望自己组织列或者不希望有标题这样方便其它程序解析结果等这就用到了 [Go 的模板语法](https://gohugo.io/templates/go-templates/)。
In some other occasions, we may not be content with the table structure and would like to reorganize the columns. In this case, we can use the [Go Templates](https://gohugo.io/templates/go-templates/).
比如下面的命令会直接列出镜像结果并且只包含镜像ID和仓库名
For example, using the following commands will list the image results, with only image ID and repository names.
```bash
$ docker image ls --format "{{.ID}}: {{.Repository}}"
@ -138,7 +138,7 @@ f753707788c5: ubuntu
1e0c3dd64ccd: ubuntu
```
或者打算以表格等距显示并且有标题行和默认一样不过自己定义列
Or we may want to show the table with equal horizontal tabulations and with title, we can define them by ourselves.
```bash
$ docker image ls --format "table {{.ID}}\t{{.Repository}}\t{{.Tag}}"

View File

@ -1,6 +1,6 @@
## Install Docker CE on Ubuntu
> warning: Don't install Docker CE directly using apt without configuring Docker APT source.
> WARNING: DO NOT install Docker CE directly using apt without configuring Docker APT source.
### Prerequisites