非常教程

Docker 17参考手册

引擎 | Engine

创建基本映像(引擎) | Create a base image (Engine)

大多数Dockerfiles从父映像开始。如果您需要完全控制图像的内容,则可能需要创建基本图像。以下是区别:

  • 一个父映像是你的形象是基于图像。它FROM指向Dockerfile中指令的内容。Dockerfile中的每个后续声明都会修改此父图像。大多数Dockerfiles从父映像开始,而不是基本映像。但是,这些术语有时可以互换使用。
  • 一个基本图像要么不具有FROM线在其Dockerfile,或具有FROM scratch

本主题向您展示了创建基础图像的几种方法。具体的过程将在很大程度上取决于你想打包的 Linux发行版。我们在下面有一些例子,并鼓励您提交拉取请求以提供新的请求。

使用tar创建一个完整的图像

一般来说,您需要从一台运行您希望打包为父映像的发行版的工作机器开始,不过对于像 Debian 的 Debootstrap 这样的工具来说,这并不是必需的,您也可以使用它来构建 Ubuntu 映像。

它可以像创建 Ubuntu 父图像一样简单:

$ sudo debootstrap xenial xenial > /dev/null
$ sudo tar -C xenial -c . | docker import - xenial

a29c15f1bf7a

$ docker run xenial cat /etc/lsb-release

DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=16.04
DISTRIB_CODENAME=xenial
DISTRIB_DESCRIPTION="Ubuntu 16.04 LTS"

在 Docker GitHub Repo 中有更多用于创建父图像的示例脚本:

  • BusyBox
  • 在Debian / Ubuntu 或 CentOS / RHEL / SLC /等上的 CentOS / Scientific Linux CERN(SLC)。
  • Debian/Ubuntu

使用scratch创建一个简单的父图像

您可以使用 Docker 的保留最小图像scratch作为构建容器的起点。使用scratch“图像”信号构建过程,您希望其中的下一个命令Dockerfile成为图像中的第一个文件系统层。

scratch出现在集线器上的 Docker 存储库中时,您无法将其拉出,运行或标记具有该名称的任何图像scratch。相反,你可以参考你的Dockerfile。例如,要使用scratch以下命令创建最小容器:

FROM scratch
ADD hello /
CMD ["/hello"]

假设您从Docker GitHub示例C源代码构建了“hello”可执行示例,并且使用该-static标记编译了该示例,则可以使用以下命令构建此 Docker 映像:docker build --tag hello .

注意:由于 Docker for Mac 和 Docker for Windows 使用 Linux VM,因此必须使用 Linux 工具链编译此代码,以最终形成 Linux 二进制文件。不用担心,您可以快速下载 Linux 映像和构建环境并在其中构建:

$ docker run --rm -it -v $PWD:/build ubuntu:16.04
container# apt-get update && apt-get install build-essential
container# cd /build
container# gcc -o hello -static -nostartfiles hello.c

然后,您可以使用以下命令运行它(在 Linux,Mac 或 Windows 上): docker run --rm hello

本示例将创建教程中使用的 hello-world 图像。如果你想测试它,你可以克隆图像回购。

更多资源

有更多的资源可以帮助你写你的Dockerfile

  • Dockerfile有关参考部分中可用于a的所有说明的完整指南。
  • 为了帮助您编写清晰,可读,可维护的文档Dockerfile,我们还编写了Dockerfile最佳实践指南。
  • 如果您的目标是创建一个新的官方存储库,请务必阅读Docker的官方存储库。

图像,基础图像,例子

引擎 | Engine相关

1..NET核心应用程序(引擎) | .NET Core application (Engine)
2.关于图像,容器和存储驱动程序(引擎) | About images, containers, and storage drivers (Engine)
3.向swarm添加节点(Engine) | Add nodes to the swarm (Engine)
4.应用自定义元数据(引擎) | Apply custom metadata (Engine)
5.应用滚动更新(引擎) | Apply rolling updates (Engine)
6.apt-cacher-ng
7.编写Dockerfiles(引擎)的最佳实践 | Best practices for writing Dockerfiles (Engine)
8.二进制(引擎) | Binaries (Engine)
9.将容器端口绑定到主机(引擎) | Bind container ports to the host (Engine)
10.突破性变化(引擎) | Breaking changes (Engine)
11.建立自己的网桥 | Build your own bridge (Engine)
12.CentOS (Engine)
13.CentOS (Engine)
14.配置容器DNS(引擎) | Configure container DNS (Engine)
15.在用户定义的网络中配置容器DNS(引擎) | Configure container DNS in user-defined networks (Engine)
16.CouchDB (Engine)
17.创建群(引擎) | Create a swarm (Engine)
18.自定义docker0网桥(引擎) | Customize the docker0 bridge (Engine)
19.Debian (Engine)
20.默认桥接网络 | Default bridge network
21.删除服务(引擎) | Delete the service (Engine)
22.部署服务(引擎) | Deploy a service (Engine)
23.将服务部署到一个群(引擎) | Deploy services to a swarm (Engine)
24.不推荐的引擎功能 | Deprecated Engine features
25.Docker容器网络(引擎) | Docker container networking (Engine)
26.Docker概述(引擎) | Docker overview (Engine)
27.Docker运行参考(引擎) | Docker run reference (Engine)
28.Dockerfile引用(引擎) | Dockerfile reference (Engine)
29.Dockerize应用程序 | Dockerize an application
30.排空节点(引擎) | Drain a node (Engine)
31.引擎 | Engine
32.FAQ(引擎) | FAQ (Engine)
33.Fedora (Engine)
34.开始 | Get started (Engine)
35.开始使用macvlan网络驱动程序 | Get started with macvlan network driver (Engine)
36.开始使用多主机网络 | Get started with multi-host networking (Engine)
37.节点如何工作 | How nodes work (Engine)
38.服务如何运作(引擎) | How services work (Engine)
39.图像管理 | Image management (Engine)
40.检查服务(引擎) | Inspect the service (Engine)
41.安装Docker(引擎) | Install Docker (Engine)
42.IPv6与Docker(引擎) | IPv6 with Docker (Engine)
43.将节点加入群集(引擎) | Join nodes to a swarm (Engine)
44.旧容器链接(引擎) | Legacy container links (Engine)
45.锁定你的群(引擎) | Lock your swarm (Engine)
46.管理群中的节点(引擎) | Manage nodes in a swarm (Engine)
47.使用Docker机密管理敏感数据(引擎) | Manage sensitive data with Docker secrets (Engine)
48.使用PKI管理swarm安全性(引擎) | Manage swarm security with PKI (Engine)
49.管理群体服务网络(引擎) | Manage swarm service networks (Engine)
50.迁移到引擎1.10 | Migrate to Engine 1.10
51.可选的Linux安装后步骤(引擎) | Optional Linux post-installation steps (Engine)
52.总览 | Overview (Engine)
53.总览 | Overview (Engine)
54.PostgreSQL(引擎) | PostgreSQL (Engine)
55.群集模式中的筏共识(引擎) | Raft consensus in swarm mode (Engine)
56.Riak (Engine)
57.以群集模式运行Docker Engine | Run Docker Engine in swarm mode
58.扩展服务(引擎) | Scale the service (Engine)
59.SDKs (Engine)
60.选择一个存储驱动 | Select a storage driver (Engine)
61.设置教程(引擎) | Set up for the tutorial (Engine)
62.SSHd (Engine)
63.存储驱动总览 | Storage driver overview (Engine)
64.存储服务配置数据(引擎) | Store service configuration data (Engine)
65.Swarm管理指南(引擎) | Swarm administration guide (Engine)
66.Swarm模式关键概念(引擎) | Swarm mode key concepts (Engine)
67.Swarm模式覆盖网络安全模型(引擎) | Swarm mode overlay network security model (Engine)
68.群模式概述(引擎) | Swarm mode overview (Engine)
69.Ubuntu (Engine)
70.Ubuntu (Engine)
71.了解容器通信(引擎) | Understand container communication (Engine)
72.使用多阶段构建(引擎) | Use multi-stage builds (Engine)
73.使用swarm模式路由网格(引擎) | Use swarm mode routing mesh (Engine)
74.使用AUFS存储驱动程序(引擎) | Use the AUFS storage driver (Engine)
75.使用Btrfs存储驱动程序(引擎) | Use the Btrfs storage driver (Engine)
76.使用设备映射器存储驱动程序(引擎) | Use the Device mapper storage driver (Engine)
77.使用OverlayFS存储驱动程序(引擎) | Use the OverlayFS storage driver (Engine)
78.使用VFS存储驱动程序(引擎) | Use the VFS storage driver (Engine)
79.使用ZFS存储驱动程序(引擎) | Use the ZFS storage driver (Engine)
80.处理图像 | Work with images
81.使用网络命令(引擎) | Work with network commands (Engine)
Docker 17

Docker 是一个开源的应用容器引擎,让开发者可以打包他们的应用以及依赖包到一个可移植的容器中,然后发布到任何流行的 Linux 机器上,也可以实现虚拟化。容器是完全使用沙箱机制,相互之间不会有任何接口。

主页 https://docker.com/
源码 https://github.com/docker/docker
版本 17
发布版本 17.06