mirror of
https://github.com/yeasy/docker_practice.git
synced 2024-12-26 15:06:18 +00:00
commit
3b0f3c0cb2
@ -7,7 +7,7 @@
|
||||
| 语言 | 构建状态 | - |
|
||||
| :------------- | :------------- | :--- |
|
||||
| [zh-hans](https://github.com/yeasy/docker_practice) | [![](https://travis-ci.org/yeasy/docker_practice.svg?branch=master)](https://travis-ci.org/yeasy/docker_practice)| [阅读](https://docker_practice.gitee.io/zh-cn) |
|
||||
| [us-en](https://github.com/yeasy/docker_practice/tree/english) | [![](https://travis-ci.org/yeasy/docker_practice.svg?branch=english)](https://travis-ci.org/yeasy/docker_practice)| [阅读](https://docker_practice.gitee.io/us_en) |
|
||||
| [us-en](https://github.com/yeasy/docker_practice/tree/english) | [![](https://travis-ci.org/yeasy/docker_practice.svg?branch=english)](https://travis-ci.org/yeasy/docker_practice)| [阅读](https://docker_practice.gitee.io/us-en) |
|
||||
| [zh-hant](https://github.com/yeasy/docker_practice/tree/zh-Hant) | [![](https://travis-ci.org/yeasy/docker_practice.svg?branch=zh-hant)](https://travis-ci.org/yeasy/docker_practice)| [阅读](https://docker_practice.gitee.io/zh_hant) |
|
||||
|
||||
[Docker](https://www.docker.com) 是个划时代的开源项目,它彻底释放了计算虚拟化的威力,极大提高了应用的维护效率,降低了云计算应用开发的成本!使用 Docker,可以让应用的部署、测试和分发都变得前所未有的高效和轻松!
|
||||
|
@ -1,7 +1,7 @@
|
||||
# 基本概念
|
||||
Docker 包括三个基本概念
|
||||
* 镜像(`Image`)
|
||||
* 容器(`Container`)
|
||||
* 仓库(`Repository`)
|
||||
# Basic Concepts
|
||||
Docker contains 3 basic concepts
|
||||
* `Image`
|
||||
* `Container`
|
||||
* `Repository`
|
||||
|
||||
理解了这三个概念,就理解了 Docker 的整个生命周期。
|
||||
Only after knowing the above 3 concepts will we get a deeper understanding of the lifecyle of docker.
|
||||
|
@ -1,13 +1,13 @@
|
||||
## Docker 容器
|
||||
## Docker Container
|
||||
|
||||
镜像(`Image`)和容器(`Container`)的关系,就像是面向对象程序设计中的 `类` 和 `实例` 一样,镜像是静态的定义,容器是镜像运行时的实体。容器可以被创建、启动、停止、删除、暂停等。
|
||||
The relationship between `Image` and `Container` is just as `Class` and `Instance` in [OOP](https://en.wikipedia.org/wiki/Object-oriented_programming). `Image` is the static definition of `container`, while `containers` are the `images` in running state. `Containers` can be created, started, paused, deleted or stopped.
|
||||
|
||||
容器的实质是进程,但与直接在宿主执行的进程不同,容器进程运行于属于自己的独立的 [命名空间](https://en.wikipedia.org/wiki/Linux_namespaces)。因此容器可以拥有自己的 `root` 文件系统、自己的网络配置、自己的进程空间,甚至自己的用户 ID 空间。容器内的进程是运行在一个隔离的环境里,使用起来,就好像是在一个独立于宿主的系统下操作一样。这种特性使得容器封装的应用比直接在宿主运行更加安全。也因为这种隔离的特性,很多人初学 Docker 时常常会混淆容器和虚拟机。
|
||||
The essence of `container` is `process`, but different from that in the host OS, the container processes run in their individual [`namespaces`](https://en.wikipedia.org/wiki/Linux_namespaces). With the namespace, a container can have its own `root` filesystem, network configurations, process space and even an ID sapce for users. The processes in a container run in an isolated environment, thus can be used as if it were an individual OS independent of the host OS. This feature makes docker-encapsulated applications safer than those running directly on the host. And that's also an important factor that confuses the novices to tell it from virtual machines.
|
||||
|
||||
前面讲过镜像使用的是分层存储,容器也是如此。每一个容器运行时,是以镜像为基础层,在其上创建一个当前容器的存储层,我们可以称这个为容器运行时读写而准备的存储层为 **容器存储层**。
|
||||
As we've discussed, `multi-layered filesystem` is applied to images, and so as the containers. When a container is running, it is based on its image, with a writable layer created on top of it. We call this layer prepared for R/W at runtime [**`Container Layer`**](https://docs.docker.com/storage/storagedriver/#images-and-layers).
|
||||
|
||||
容器存储层的生存周期和容器一样,容器消亡时,容器存储层也随之消亡。因此,任何保存于容器存储层的信息都会随容器删除而丢失。
|
||||
The lifecyle of the container layer is the same as contaier. The container layer dies as soon as the container dies. Therefore, anything stored at the container layer will be discarded when the container is deleted.
|
||||
|
||||
按照 Docker 最佳实践的要求,容器不应该向其存储层内写入任何数据,容器存储层要保持无状态化。所有的文件写入操作,都应该使用 [数据卷(Volume)](../data_management/volume.md)、或者绑定宿主目录,在这些位置的读写会跳过容器存储层,直接对宿主(或网络存储)发生读写,其性能和稳定性更高。
|
||||
As recommended by the [Docker Development Best Practices](https://docs.docker.com/develop/dev-best-practices/#where-and-how-to-persist-application-data), we should not write any data to the container layer to make it stateless. All file write operations should adhere to [`Volume`](../data_management/volume.md) or bind mounts. Writing to volume or bind mounts skips the container layer and R/W to host storage(or network storage) directly, which achieves better performance and stability.
|
||||
|
||||
数据卷的生存周期独立于容器,容器消亡,数据卷不会消亡。因此,使用数据卷后,容器删除或者重新运行之后,数据却不会丢失。
|
||||
The lifecyle of volume is independent of the container, and will not vanish when the container is deleted. In light of it, the data persists when a container is deleted or restarted.
|
||||
|
@ -1,29 +1,29 @@
|
||||
## Docker Registry
|
||||
|
||||
镜像构建完成后,可以很容易的在当前宿主机上运行,但是,如果需要在其它服务器上使用这个镜像,我们就需要一个集中的存储、分发镜像的服务,[Docker Registry](../repository/registry.md) 就是这样的服务。
|
||||
After the construction of an image, we can easily run it on a host. However, if we want to use the image on other servers, we need a centralized image storage and distribution service. The [Docker Registry](../repository/registry.md) we will introduce is such a service.
|
||||
|
||||
一个 **Docker Registry** 中可以包含多个 **仓库**(`Repository`);每个仓库可以包含多个 **标签**(`Tag`);每个标签对应一个镜像。
|
||||
A **Docker Registry** can contain several `Repositories`, where each repository can contain several tags and each tag corresponds to an image.
|
||||
|
||||
通常,一个仓库会包含同一个软件不同版本的镜像,而标签就常用于对应该软件的各个版本。我们可以通过 `<仓库名>:<标签>` 的格式来指定具体是这个软件哪个版本的镜像。如果不给出标签,将以 `latest` 作为默认标签。
|
||||
Typically, a repository contains images for different versions of the same software, where each tags corresponds to different versions of the software. We can uniquely identify an image of the same software with `repository:tag`. In case not explicitly specified, `latest` is taken as default tag.
|
||||
|
||||
以 [Ubuntu 镜像](https://hub.docker.com/_/ubuntu) 为例,`ubuntu` 是仓库的名字,其内包含有不同的版本标签,如,`16.04`, `18.04`。我们可以通过 `ubuntu:16.04`,或者 `ubuntu:18.04` 来具体指定所需哪个版本的镜像。如果忽略了标签,比如 `ubuntu`,那将视为 `ubuntu:latest`。
|
||||
Taking the [Ubuntu Image](https://hub.docker.com/_/ubuntu) as an example. `ubuntu` is the name for repository, and inside it are tags for different versions, for instance, `16.04`, `18.04`. We can use `ubuntu:16.04` or `ubuntu:18.04` to specify the particular image we want. If the tag is omitted, for example, `ubuntu`, then it will be considered as `ubuntu:latest`.
|
||||
|
||||
仓库名经常以 *两段式路径* 形式出现,比如 `jwilder/nginx-proxy`,前者往往意味着 Docker Registry 多用户环境下的用户名,后者则往往是对应的软件名。但这并非绝对,取决于所使用的具体 Docker Registry 的软件或服务。
|
||||
Repository name is typically seperated by a forward slash(/), for example, `jwilder/nginx-proxy`, the former is to identify a particular user in a multi-user Docker Registry, while the latter corresponds to the software name. But it is not always the case. It also depends on the Docker Registry software or service you are using.
|
||||
|
||||
### Docker Registry 公开服务
|
||||
### Docker Registry Public Services
|
||||
|
||||
Docker Registry 公开服务是开放给用户使用、允许用户管理镜像的 Registry 服务。一般这类公开服务允许用户免费上传、下载公开的镜像,并可能提供收费服务供用户管理私有镜像。
|
||||
`Docker Registry Public Services` are registry services open to users, allowing users to manage their images. Typically, those public services offer user free image uploads and downloads, and possibly provide charged service for privately managed images.
|
||||
|
||||
最常使用的 Registry 公开服务是官方的 [Docker Hub](https://hub.docker.com/),这也是默认的 Registry,并拥有大量的高质量的官方镜像。除此以外,还有 [CoreOS](https://coreos.com/) 的 [Quay.io](https://quay.io/repository/),CoreOS 相关的镜像存储在这里;Google 的 [Google Container Registry](https://cloud.google.com/container-registry/),[Kubernetes](https://kubernetes.io/) 的镜像使用的就是这个服务。
|
||||
The most commonly used registry public service is the official [Docker Hub](https://hub.docker.com/), which is the default registry with thousands of high quality official images. Besides, the images for [Quay.io](https://quay.io/repository/) and CoreOS of [CoreOS](https://coreos.com/) are stored there. Google's [Google Container Registry](https://cloud.google.com/container-registry/) and [Kubernetes](https://kubernetes.io/) also use this service.
|
||||
|
||||
由于某些原因,在国内访问这些服务可能会比较慢。国内的一些云服务商提供了针对 Docker Hub 的镜像服务(`Registry Mirror`),这些镜像服务被称为**加速器**。常见的有 [阿里云加速器](https://cr.console.aliyun.com/#/accelerator)、[DaoCloud 加速器](https://www.daocloud.io/mirror#accelerator-doc) 等。使用加速器会直接从国内的地址下载 Docker Hub 的镜像,比直接从 Docker Hub 下载速度会提高很多。在 [安装 Docker](../install/mirror.md) 一节中有详细的配置方法。
|
||||
Due to some reasons knwon to all, accessing those services from China mainland is slow. There are some cloud service providers in China providing `Registry Mirror` for Docker Hub, those mirror services are called `accelerators`. The well-known ones are [Ali Cloud Image Accelerator](https://cr.console.aliyun.com/#/accelerator) and [DaoCloud Accelerator](https://www.daocloud.io/mirror#accelerator-doc). In China, downloading from these services are much faster than from Docker Hub. The detailed image source configuration tutorial is in the [Docker Installation](../install/mirror.md) section.
|
||||
|
||||
国内也有一些云服务商提供类似于 Docker Hub 的公开服务。比如 [时速云镜像仓库](https://hub.tenxcloud.com/)、[网易云镜像服务](https://c.163.com/hub#/m/library/)、[DaoCloud 镜像市场](https://hub.daocloud.io/)、[阿里云镜像库](https://cr.console.aliyun.com) 等。
|
||||
There are also some cloud service providers that provide public services similar to Docker Hub in China. For example, [Tenxcloud Mirror Registry](https://hub.tenxcloud.com/), [NetEase Mirror Registry](https://c.163.com/hub#/m/library/), [DaoCloud Mirror Market](https://hub.daocloud.io/), [Ali Cloud Mirror Registry](https://cr.console.aliyun.com), etc.
|
||||
|
||||
### 私有 Docker Registry
|
||||
### Private Docker Registry
|
||||
|
||||
除了使用公开服务外,用户还可以在本地搭建私有 Docker Registry。Docker 官方提供了 [Docker Registry](https://hub.docker.com/_/registry/) 镜像,可以直接使用做为私有 Registry 服务。在 [私有仓库](../repository/registry.md) 一节中,会有进一步的搭建私有 Registry 服务的讲解。
|
||||
Apart from using public service, a user can set up private Docker Registry. Docker offical offers the [Docker Registry](https://hub.docker.com/_/registry/) docker image, which can be deployed for private registry service. We will explain how to set it up in detail in the [Private Registry](../repository/registry.md) section.
|
||||
|
||||
开源的 Docker Registry 镜像只提供了 [Docker Registry API](https://docs.docker.com/registry/spec/api/) 的服务端实现,足以支持 `docker` 命令,不影响使用。但不包含图形界面,以及镜像维护、用户管理、访问控制等高级功能。在官方的商业化版本 [Docker Trusted Registry](https://docs.docker.com/datacenter/dtr/2.0/) 中,提供了这些高级功能。
|
||||
The open source Docker Registry image only provides the backend of [Docker Registry API](https://docs.docker.com/registry/spec/api/), which supports the `docker` commands and is enough for personal use, although the advanced functionalities like GUI(Graphical User Interface), Image Maintenance and Access Control are not supported. However, they are provided in the commercial version - [Docker Trusted Registry](https://docs.docker.com/datacenter/dtr/2.0/).
|
||||
|
||||
除了官方的 Docker Registry 外,还有第三方软件实现了 Docker Registry API,甚至提供了用户界面以及一些高级功能。比如,[Harbor](https://github.com/goharbor/harbor) 和 [Sonatype Nexus](../repository/nexus3_registry.md)。
|
||||
Except for the official Docker Registry, there are third-party softwares that implement Docker Registry API, even with some advanced features like user interface. For example, [Harbor](https://github.com/goharbor/harbor) and [Sonatype Nexus](../repository/nexus3_registry.md).
|
||||
|
Loading…
Reference in New Issue
Block a user