Skip to Content
Docker:入门与实践,第三版
book

Docker:入门与实践,第三版

by Sean P. Kane, Karl Matthias
May 2025
Intermediate to advanced
418 pages
5h 47m
Chinese
O'Reilly Media, Inc.
Content preview from Docker:入门与实践,第三版

第 6 章 探索 Docker 探索 Docker

本作品已使用人工智能进行翻译。欢迎您提供反馈和意见:translation-feedback@oreilly.com

现在,你已经有了一些使用容器和镜像的经验,我们可以探索一些 Docker 的其他功能了。在本章中,我们将继续使用docker 命令行工具与你配置的运行中的dockerd 服务器对话,同时访问一些其他基本命令。

Docker 提供的命令可以轻松完成其他几件事:

  • 打印 Docker 版本

  • 查看服务器信息

  • 下载图像更新

  • 检查集装箱

  • 进入运行中的容器

  • 返回结果

  • 查看日志

  • 监测统计数据

  • 还有更多

让我们来看看这些工具以及一些增强Docker 本机功能的其他社区工具。

打印 Docker 版本

如果你完成了上一章的学习,那么你已经在 Linux 服务器或虚拟机上安装了一个正常运行的 Docker 守护进程,并启动了一个基础容器以确保一切正常。如果你还没有设置好基础容器,又想尝试本书后面的步骤,那么在继续本节内容之前,请先按照第 3 章的安装步骤进行操作。

使用 Docker 可以做的最简单的事情就是打印各种组件的版本。这听起来似乎没什么,但这却是一个非常有用的工具,因为 Docker 是由众多组件构建而成的,这些组件的版本将直接决定您可以使用哪些功能。了解如何显示版本还有助于排除客户端和服务器之间某些类型的连接问题。例如,Docker 客户端可能会给你一条关于 API 版本不匹配的隐晦信息,如果能将其转换为 Docker 版本就更好了,这样你就能知道哪个组件需要更新。该命令与远程 Docker 服务器对话,因此如果客户端因故无法连接到服务器,客户端就会报错,然后只打印出客户端版本信息。如果你发现连接有问题,也许应该重温上一章中的步骤。

备注

如果您正在排除故障,或者只是不想使用docker 客户端连接到远程系统,您总是可以直接登录到 Docker 服务器 ,然后从服务器上的 shell 运行docker 命令。在大多数 Docker 服务器上,这需要root 权限或docker 组的成员身份,才能连接到 Docker 正在监听的 Unix 域套接字。

由于我们刚刚同时安装了所有 Docker 组件,因此当我们运行docker version 时,应该会看到所有版本都是一致的:

$ docker version
Client:
 Cloud integration: v1.0.24
 Version:           20.10.17
 API version:       1.41
 Go version:        go1.17.11
 Git commit:        100c701
 Built:             Mon Jun  6 23:04:45 2022
 OS/Arch:           darwin/amd64
 Context:           default
 Experimental:      true

Server: Docker Desktop 4.10.1 (82475)
 Engine:
  Version:          20.10.17
  API version:      1.41 (minimum version 1.12)
  Go version:       go1.17.11
  Git commit:       a89b842
  Built:            Mon Jun  6 23:01:23 2022
  OS/Arch:          linux/amd64
  Experimental:     false
 containerd:
  Version:          1.6.6
 GitCommit: ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

人工智能技术与大数据

人工智能技术与大数据

Posts & Telecom Press, Anand Deshpande, Manish Kumar
超越Vibe编程

超越Vibe编程

Addy Osmani
写给系统管理员的Python脚本编程指南

写给系统管理员的Python脚本编程指南

Posts & Telecom Press, Ganesh Sanjiv Naik

Publisher Resources

ISBN: 9798341656826