Java interview review summarizes the core concepts --Docker

table of Contents

Start with a beginning understanding of container

1.1 What is a container?

1.2 illustrates a physical machine, the virtual machine container

Two come to talk about some of the concepts of Docker

2.1 What is the Docker?

2.2 Docker thought

Features 2.3 Docker container

2.4 Why Docker

Three Tank VS virtual machine

3.1 Comparison between the two in FIG.

3.2 container with a virtual machine (VM) summary

3.3 with the container virtual machine (VM) both can coexist

Docker four basic concepts

4.1 mirror (Image) - a special file system

4.2 the container (Container) - mirror entity runtime

Centralized place to store image files - 4.3 repository (Repository)

The last five talk: Build, Ship, and Run

Six summary


This article is the concept of Docker's do a more detailed introduction, does not involve some of the common commands like installation and operating environment and Docker Docker's.

Read this article takes about 15 minutes, by reading this article you will know about the concept:

  • container
  • What is the Docker?
  • Docker thought, Features
  • Docker containers mainly to solve the problem
  • VS virtual machine container
  • Docker basic concepts: the mirror (Image), the container (Container), the warehouse (the Repository)

Docker is the world's leading software platform container, so I want to get to know the concept of Docker we must begin to start talking about container.

Start with a beginning understanding of container

1.1 What is a container?

Let's look more official explanation container

Sentence container: container is packaging software into a standardized unit for the development, delivery and deployment.

  • Mirroring container is lightweight, standalone executable package that contains everything you need to run the software: code, run-time environment, system tools, system libraries and settings.
  • Containerized software for Linux and Windows-based applications, are able to consistently run in any environment.
  • Container gives software independence from the effects of external environmental differences (eg, differences in the development and rehearsal environment), thus helping to reduce conflicts between teams running different software on the same infrastructure.

Let's look at the more popular explanation container

If you need to describe in simple containers, I think that is where a container for storing things like bag can hold all kinds of stationery, wardrobe can put all kinds of clothes, shoe racks can put all kinds of shoes the same. We are talking about something container storage may prefer to use such sites, and even program the system environment.

Understanding of container

1.2 illustrates a physical machine, the virtual machine container

Contrasting virtual machines and containers in more detail later introduced to, here only deepen the understanding of the physical machines, virtual machines and containers by these three pictures online.

Physical machine

Physical machine

virtual machine:

virtual machine

container:

container

Through the above three abstract view of this, we can probably be summarized by analogy: Container virtualization is between the operating system rather than the hardware, the containers are sharing the same set of operating system resources. After the virtual virtual machine technology is a set of hardware, run a full operating system on it. Therefore container isolation level will be slightly lower.


I believe that through the above explanation we have a preliminary understanding of this vessel both strange and familiar with the concept, here we come to talk about some of the concepts Docker.

Two come to talk about some of the concepts of Docker

Some of the concepts Docker

2.1 What is the Docker?

To tell the truth about what is and Docker good to say, here I explain to you by four points Docker in the end is what.

  • Docker is the world's leading software platform container.
  • Docker use Google launched the Go language development to achieve, based on cgroup, namespace, and UnionFS AUFS class technology such as the Linux kernel, the process of encapsulation isolation, belonging to the virtualization operating system level. Since the isolation process independently of the host and other isolation processes, and therefore also referred to as a container. Docke initial implementation is based on LXC.
  • Docker can automate repetitive tasks such as set up and configure the development environment, which frees developers so that they can focus on the really important things: building great software.
  • Users can easily create and use a container, put their applications into the container. The container may also be version management, copying, sharing, modifying, managing general code like the same.

What is the Docker

2.2 Docker thought

  • container
  • Standardization: ① ② transportation storage ③ API Interface
  • isolation

Features 2.3 Docker container

  • Lightweight

    在一台机器上运行的多个 Docker 容器可以共享这台机器的操作系统内核;它们能够迅速启动,只需占用很少的计算和内存资源。镜像是通过文件系统层进行构造的,并共享一些公共文件。这样就能尽量降低磁盘用量,并能更快地下载镜像。

  • 标准

    Docker 容器基于开放式标准,能够在所有主流 Linux 版本、Microsoft Windows 以及包括 VM、裸机服务器和云在内的任何基础设施上运行。

  • 安全

    Docker 赋予应用的隔离性不仅限于彼此隔离,还独立于底层的基础设施。Docker 默认提供最强的隔离,因此应用出现问题,也只是单个容器的问题,而不会波及到整台机器。

2.4 为什么要用Docker

  • Docker 的镜像提供了除内核外完整的运行时环境,确保了应用运行环境一致性,从而不会再出现 “这段代码在我机器上没问题啊” 这类问题;——一致的运行环境
  • 可以做到秒级、甚至毫秒级的启动时间。大大的节约了开发、测试、部署的时间。——更快速的启动时间
  • 避免公用的服务器,资源会容易受到其他用户的影响。——隔离性
  • 善于处理集中爆发的服务器使用压力;——弹性伸缩,快速扩展
  • 可以很轻易的将在一个平台上运行的应用,迁移到另一个平台上,而不用担心运行环境的变化导致应用无法正常运行的情况。——迁移方便
  • 使用 Docker 可以通过定制应用镜像来实现持续集成、持续交付、部署。——持续交付和部署

每当说起容器,我们不得不将其与虚拟机做一个比较。就我而言,对于两者无所谓谁会取代谁,而是两者可以和谐共存。

三 容器 VS 虚拟机

  简单来说: 容器和虚拟机具有相似的资源隔离和分配优势,但功能有所不同,因为容器虚拟化的是操作系统,而不是硬件,因此容器更容易移植,效率也更高。

3.1 两者对比图

  传统虚拟机技术是虚拟出一套硬件后,在其上运行一个完整操作系统,在该系统上再运行所需应用进程;而容器内的应用进程直接运行于宿主的内核,容器内没有自己的内核,而且也没有进行硬件虚拟。因此容器要比传统虚拟机更为轻便.

VS virtual machine container

3.2 容器与虚拟机 (VM) 总结

Container with a virtual machine (VM) summary

  • 容器是一个应用层抽象,用于将代码和依赖资源打包在一起。 多个容器可以在同一台机器上运行,共享操作系统内核,但各自作为独立的进程在用户空间中运行 。与虚拟机相比, 容器占用的空间较少(容器镜像大小通常只有几十兆),瞬间就能完成启动 。

  • 虚拟机 (VM) 是一个物理硬件层抽象,用于将一台服务器变成多台服务器。 管理程序允许多个 VM 在一台机器上运行。每个VM都包含一整套操作系统、一个或多个应用、必要的二进制文件和库资源,因此 占用大量空间 。而且 VM 启动也十分缓慢 。

  通过Docker官网,我们知道了这么多Docker的优势,但是大家也没有必要完全否定虚拟机技术,因为两者有不同的使用场景。虚拟机更擅长于彻底隔离整个运行环境。例如,云服务提供商通常采用虚拟机技术隔离不同的用户。而 Docker通常用于隔离不同的应用 ,例如前端,后端以及数据库。

3.3 容器与虚拟机 (VM)两者是可以共存的

就我而言,对于两者无所谓谁会取代谁,而是两者可以和谐共存。

Both can coexist


Docker中非常重要的三个基本概念,理解了这三个概念,就理解了 Docker 的整个生命周期。

四 Docker基本概念

Docker 包括三个基本概念

  • 镜像(Image)
  • 容器(Container)
  • 仓库(Repository)

理解了这三个概念,就理解了 Docker 的整个生命周期

Docker includes three basic concepts

4.1 镜像(Image)——一个特殊的文件系统

  操作系统分为内核和用户空间。对于 Linux 而言,内核启动后,会挂载 root 文件系统为其提供用户空间支持。而Docker 镜像(Image),就相当于是一个 root 文件系统。

  Docker 镜像是一个特殊的文件系统,除了提供容器运行时所需的程序、库、资源、配置等文件外,还包含了一些为运行时准备的一些配置参数(如匿名卷、环境变量、用户等)。 镜像不包含任何动态数据,其内容在构建之后也不会被改变。

  Docker 设计时,就充分利用 Union FS的技术,将其设计为 分层存储的架构 。 镜像实际是由多层文件系统联合组成。

  镜像构建时,会一层层构建,前一层是后一层的基础。每一层构建完就不会再发生改变,后一层上的任何改变只发生在自己这一层。 比如,删除前一层文件的操作,实际不是真的删除前一层的文件,而是仅在当前层标记为该文件已删除。在最终容器运行的时候,虽然不会看到这个文件,但是实际上该文件会一直跟随镜像。因此,在构建镜像的时候,需要额外小心,每一层尽量只包含该层需要添加的东西,任何额外的东西应该在该层构建结束前清理掉。

  分层存储的特征还使得镜像的复用、定制变的更为容易。甚至可以用之前构建好的镜像作为基础层,然后进一步添加新的层,以定制自己所需的内容,构建新的镜像。

4.2 容器(Container)——镜像运行时的实体

  镜像(Image)和容器(Container)的关系,就像是面向对象程序设计中的 类 和 实例 一样,镜像是静态的定义,容器是镜像运行时的实体。容器可以被创建、启动、停止、删除、暂停等。

  容器的实质是进程,但与直接在宿主执行的进程不同,容器进程运行于属于自己的独立的 命名空间。前面讲过镜像使用的是分层存储,容器也是如此。

  容器存储层的生存周期和容器一样,容器消亡时,容器存储层也随之消亡。因此,任何保存于容器存储层的信息都会随容器删除而丢失。

  按照 Docker 最佳实践的要求,容器不应该向其存储层内写入任何数据 ,容器存储层要保持无状态化。所有的文件写入操作,都应该使用数据卷(Volume)、或者绑定宿主目录,在这些位置的读写会跳过容器存储层,直接对宿主(或网络存储)发生读写,其性能和稳定性更高。数据卷的生存周期独立于容器,容器消亡,数据卷不会消亡。因此, 使用数据卷后,容器可以随意删除、重新 run ,数据却不会丢失。

4.3 仓库(Repository)——集中存放镜像文件的地方

  镜像构建完成后,可以很容易的在当前宿主上运行,但是, 如果需要在其它服务器上使用这个镜像,我们就需要一个集中的存储、分发镜像的服务,Docker Registry就是这样的服务。

  一个 Docker Registry中可以包含多个仓库(Repository);每个仓库可以包含多个标签(Tag);每个标签对应一个镜像。所以说:镜像仓库是Docker用来集中存放镜像文件的地方类似于我们之前常用的代码仓库。

  通常,一个仓库会包含同一个软件不同版本的镜像,而标签就常用于对应该软件的各个版本 。我们可以通过<仓库名>:<标签>的格式来指定具体是这个软件哪个版本的镜像。如果不给出标签,将以 latest 作为默认标签.。

这里补充一下Docker Registry 公开服务和私有 Docker Registry的概念:

  Docker Registry 公开服务 是开放给用户使用、允许用户管理镜像的 Registry 服务。一般这类公开服务允许用户免费上传、下载公开的镜像,并可能提供收费服务供用户管理私有镜像。

  最常使用的 Registry 公开服务是官方的 Docker Hub ,这也是默认的 Registry,并拥有大量的高质量的官方镜像,网址为:hub.docker.com/ 。在国内访问Docker Hub 可能会比较慢国内也有一些云服务商提供类似于 Docker Hub 的公开服务。比如 时速云镜像库网易云镜像服务DaoCloud 镜像市场阿里云镜像库等。

  除了使用公开服务外,用户还可以在 本地搭建私有 Docker Registry 。Docker 官方提供了 Docker Registry 镜像,可以直接使用做为私有 Registry 服务。开源的 Docker Registry 镜像只提供了 Docker Registry API 的服务端实现,足以支持 docker 命令,不影响使用。但不包含图形界面,以及镜像维护、用户管理、访问控制等高级功能。


Docker的概念基本上已经讲完,最后我们谈谈:Build, Ship, and Run。

五 最后谈谈:Build, Ship, and Run

如果你搜索Docker官网,会发现如下的字样:“Docker - Build, Ship, and Run Any App, Anywhere”。那么Build, Ship, and Run到底是在干什么呢?

build ship run

  • Build(构建镜像) : 镜像就像是集装箱包括文件以及运行环境等等资源。
  • Ship(运输镜像) :主机和仓库间运输,这里的仓库就像是超级码头一样。
  • Run (运行镜像) :运行的镜像就是一个容器,容器就是运行程序的地方。

Docker 运行过程也就是去仓库把镜像拉到本地,然后用一条命令把镜像运行起来变成容器。所以,我们也常常将Docker称为码头工人或码头装卸工,这和Docker的中文翻译搬运工人如出一辙。

六 总结

本文主要把Docker中的一些常见概念做了详细的阐述,但是并不涉及Docker的安装、镜像的使用、容器的操作等内容。这部分东西,希望读者自己可以通过阅读书籍与官方文档的形式掌握。如果觉得官方文档阅读起来很费力的话,这里推荐一本书籍《Docker技术入门与实战第二版》。

发布了142 篇原创文章 · 获赞 31 · 访问量 2万+

Guess you like

Origin blog.csdn.net/qq_38905818/article/details/103714511