前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >【docker】入门

【docker】入门

作者头像
20岁爱吃必胜客
发布2023-03-06 13:58:51
1.4K0
发布2023-03-06 13:58:51
举报
文章被收录于专栏:进步集

注:最后有面试挑战,看看自己掌握了吗

文章目录


🌸I could be bounded in a nutshell and count myself a king of infinite space.

特别鸣谢:木芯工作室 、Ivan from Russia


docker是什么?

Docker 是一个用于开发、交付和运行应用程序的开放平台。 Docker 使您能够将应用程序与基础架构分开,以便 您可以快速交付软件。使用 Docker,您可以管理您的基础架构 以与管理应用程序相同的方式。通过利用 Docker 的 快速传送、测试和部署代码的方法,您可以 显著减少编写代码和在生产环境中运行代码之间的延迟。 Docker 提供了在松散隔离中打包和运行应用程序的能力 称为容器的环境。隔离和安全性允许您运行许多 容器同时在给定主机上容器重量轻,包含 运行应用程序所需的一切,因此您无需依赖 当前安装在主机上。您可以在工作时轻松共享容器, 并确保与您共享的每个人都获得在 同样的方式

Docker 提供了工具和平台来管理容器的生命周期

使用容器开发应用程序及其支持组件。 容器成为分发和测试应用程序的单元。 准备就绪后,将应用程序部署到生产环境中, 作为容器或编排服务。无论您的 生产环境是本地数据中心、云提供商或混合环境 两者的。

在这里插入图片描述
在这里插入图片描述

docker 美: [ˈdɑkər] 英: [ˈdɒkə®] n. 码头工人 网络 船坞工人;泊坞窗;搬运工人

dockers Some people turn up their noses if you say your father was a miner, OR docker. 要是你说你父亲当过矿工或码头工人,就会有人瞧不起你。

Docker Engine overview

容器是映像的可运行实例

Docker Engine is an open source containerization technology for building and containerizing your applications. Docker Engine acts as a client-server application with: A server with a long-running daemon process dockerd. APIs which specify interfaces that programs can use to talk to and instruct the Docker daemon. A command line interface (CLI) client docker. The CLI uses Docker APIs to control or interact with the Docker daemon through scripting or direct CLI commands. Many other Docker applications use the underlying API and CLI. The daemon creates and manage Docker objects, such as images, containers, networks, and volumes.

Docker Engine 是一种开源的集装箱化技术,用于构建和容纳应用程序。Docker Engine 作为客户机-服务器应用程序使用:

具有长时间运行的守护进程 docker 的服务器。 这些 API 指定程序可以用来与 Docker 守护进程对话和指示的接口。 命令行接口(CLI)客户端停靠程序。 CLI 使用 Docker API 通过编写脚本或直接使用 CLI 命令来控制 Docker 守护进程或与之交互。许多其他 Docker 应用程序使用底层 API 和 CLI。守护进程创建并管理 Docker 对象,例如图像、容器、网络和卷。 For more details, see Docker Architecture.


  1. 是什么:开源的应用容器引擎,而一个容器containers其实是一个虚拟化的独立的环境
  2. 作用:让开发者可以打包他们的应用以及依赖包到一个可移植的容器中,然后发布到任何流行的 Linux 机器上,也可以实现虚拟化。容器是完全使用沙箱机制,相互之间不会有任何接口
  3. 局限:它只能用在 64 位的操作系统上。

概述

本指南包含有关如何开始使用 Docker 的分步说明。您将在本指南中学习和执行的一些操作包括:

将映像作为容器生成和运行 使用 Docker Hub 共享映像 使用具有数据库的多个容器部署 Docker 应用程序 使用 Docker Compose 运行应用程序 在掌握本指南的部分内容之前,您应该了解容器和图像。

什么是容器container?

简而言之,容器是计算机上的沙盒进程,与主机上的所有其他进程隔离。这种隔离利用内核命名空间和 cgroups, 在 Linux 中已经存在很长时间的功能。Docker一直致力于使这些功能变得平易近人且易于使用。总而言之,容器:

is a runnable instance of an image。您可以使用 DockerAPI 或 CLI 创建、启动、停止、移动或删除容器。 可以在本地计算机、虚拟机上运行或部署到云中。 是可移植的(可以在任何操作系统上运行)。 与其他容器隔离,并运行自己的软件、二进制文件和配置

什么是容器映像 image?

运行容器时,它使用隔离的文件系统。此自定义文件系统由容器映像提供。由于映像包含容器的文件系统,因此它必须包含运行应用程序所需的一切 - 所有依赖项、配置、脚本、二进制文件等。该映像还包含容器的其他配置,例如环境变量、要运行的默认命令和其他元数据。

在本指南的后面部分,您将更深入地了解图像,涵盖分层、最佳做法等主题。

Note If you’re familiar with , think of a container as an extended version of . The filesystem is simply coming from the image. But, a container adds additional isolation not available when simply using chroot.chrootchroot

官方解释什么是container和container image

Docker objects

When you use Docker, you are creating and using images, containers, networks, volumes, plugins, and other objects. This section is a brief overview of some of those objects.

Images - 一个用来创建docker容器的东西-----------类

映像是一个只读模板,其中包含创建 Docker 容器的说明。通常,一个image是基于另一个图像的,带有一些额外的定制。例如,你可以构建一个基于该映像的映像,但是要安装 Apache HTTP Server 和应用程序,以及使应用程序运行所需的配置细节

您可以创建自己的映像,也可以只使用其他人创建并在注册表中发布的图像。要构建您自己的映像,您需要创建一个 Dockerfile,它使用简单的语法来定义创建和运行映像所需的步骤。Dockerfile 中的每条指令在图像中创建一个层。当您更改 Dockerfile 并重新生成映像时,只有那些已更改的层才会重新生成。与其他虚拟化技术相比,这是使映像如此轻量级、小型和快速的原因之一。

An image is a read-only template with instructions for creating a Docker container. Often, an image is based on another image, with some additional customization. For example, you may build an image which is based on the image, but installs the Apache web server and your application, as well as the configuration details needed to make your application run.ubuntu You might create your own images or you might only use those created by others and published in a registry. To build your own image, you create a Dockerfile with a simple syntax for defining the steps needed to create the image and run it. Each instruction in a Dockerfile creates a layer in the image. When you change the Dockerfile and rebuild the image, only those layers which have changed are rebuilt. This is part of what makes images so lightweight, small, and fast, when compared to other virtualization technologies.

Containers------实例(被用image创建的)

容器是映像的可运行实例。您可以使用 Docker API 或 CLI 创建、启动、停止、移动或删除容器。您可以将容器连接到一个或多个网络,将存储附加到容器,甚至可以根据其当前状态创建新映像。

默认情况下,容器与其他容器及其主机相对隔离。您可以控制容器的网络、存储或其他底层子系统与其他容器或主机的隔离程度

容器由其映像以及在创建或启动它时提供给它的任何配置选项定义。当一个容器被删除时,对其状态的任何更改都不会存储在持久性存储中。

A container is a runnable instance of an image. You can create, start, stop, move, or delete a container using the Docker API or CLI. You can connect a container to one or more networks, attach storage to it, or even create a new image based on its current state. By default, a container is relatively well isolated from other containers and its host machine. You can control how isolated a container’s network, storage, or other underlying subsystems are from other containers or from the host machine. A container is defined by its image as well as any configuration options you provide to it when you create or start it. When a container is removed, any changes to its state that are not stored in persistent storage disappear. Example commanddocker run The following command runs an container, attaches interactively to your local command-line session, and runs .ubuntu/bin/bash docker run -i -t ubuntu /bin/bash When you run this command, the following happens (assuming you are using the default registry configuration): If you do not have the image locally, Docker pulls it from your configured registry, as though you had run manually.ubuntudocker pull ubuntu Docker creates a new container, as though you had run a command manually.docker container create Docker allocates a read-write filesystem to the container, as its final layer. This allows a running container to create or modify files and directories in its local filesystem. Docker creates a network interface to connect the container to the default network, since you did not specify any networking options. This includes assigning an IP address to the container. By default, containers can connect to external networks using the host machine’s network connection. Docker starts the container and executes . Because the container is running interactively and attached to your terminal (due to the and flags), you can provide input using your keyboard while the output is logged to your terminal./bin/bash-i-t When you type to terminate the command, the container stops but is not removed. You can start it again or remove it.exit/bin/bash The underlying technology Docker is written in the Go programming language and takes advantage of several features of the Linux kernel to deliver its functionality. Docker uses a technology called to provide the isolated workspace called the container. When you run a container, Docker creates a set of namespaces for that container.namespaces These namespaces provide a layer of isolation. Each aspect of a container runs in a separate namespace and its access is limited to that namespace.

下面的命令运行一个容器,交互式地附加到本地命令行会话,并运行. ubuntu/bin/bash

代码语言:javascript
复制
$docker run-i-t ubuntu/bin/bash

运行此命令时,将发生以下情况(假设您使用默认注册表配置) :

如果没有本地映像,Docker 将从配置的注册表中提取映像,就像您已经运行了 manualy.ubuntudocker pull ubuntu 一样

Docker 创建一个新的容器,就像您运行了 manualy.Docker 容器 create 命令一样

Docker 为容器分配一个读写文件系统,作为它的最后一层。这允许运行的容器在其本地文件系统中创建或修改文件和目录

Docker 创建了一个网络接口来将容器连接到默认网络,因为您没有指定任何网络选项。这包括为容器分配一个 IP 地址。默认情况下,容器可以使用主机的网络连接连接到外部网络。

Docker 启动容器并执行。因为容器**以交互方式运行并附加到终端(**由于和标志) ,所以可以在输出记录到终端时使用键盘提供输入。/bin/bash-i-t

当您键入以终止命令时,容器将停止,但不会被移除。您可以重新启动它或者删除它

基础技术

Docker 是用 Go 编程语言编写的,它利用 Linux 内核的几个特性来提供其功能。Docker 使用一种称为容器的技术来提供隔离的工作区。当您运行一个容器时,Docker 为这个 conter.nampace 创建一组名称空间

这些名称空间提供了一个隔离层容器的每个方面都在单独的名称空间中运行,并且其访问仅限于该名称空间。

码头工人架构

Docker 使用客户端-服务器架构。Docker 客户端与 Docker 守护进程,它负责构建、运行和 分发您的 Docker 容器Docker 客户端和守护程序可以在同一系统上运行,也可以将 Docker 客户端连接到远程 Docker 守护 进程。Docker 客户端和守护程序使用 REST API 通过 UNIX 进行通信 套接字或网络接口。另一个 Docker 客户端是 Docker Compose, 这使您可以处理由一组容器组成的应用程序。

在这里插入图片描述
在这里插入图片描述

码头工人守护进程The Docker daemon

Docker 守护程序 () 侦听 Docker API 请求并管理 Docker 对象,例如映像、容器、网络和卷。守护进程也可以 与其他守护程序通信以管理 Docker 服务。dockerd The Docker daemon () listens for Docker API requests and manages Docker objects such as images, containers, networks, and volumes. A daemon can also communicate with other daemons to manage Docker services

daemon 美: [ˈdimən] 英: [ˈdiːmən] n. (古希腊神话中的)半神半人的精灵 网络 守护进程;守护程序;虚拟光驱 词形: daemons daemones Each daemon usually has its own log file, which makes it easy to hunt down issues when a service fails.

通常,每个守护进程都拥有自己的日志文件,这使得当一个服务失败时很容易搜寻所发生的问题。

码头工人客户端

Docker 客户端 () 是许多 Docker 用户交互的主要方式 与 Docker 一起。当您使用诸如 的命令时,客户端会发送这些命令 命令到 ,执行这些命令。该命令使用 Docker API。Docker 客户端可以与多个守护程序通信。dockerdocker rundockerddocker

码头工人桌面

Docker Desktop 是一款易于安装的应用程序,适用于您的 Mac、Windows 或 Linux 环境,使您能够构建和共享容器化应用程序和微服务。Docker Desktop 包括 Docker 守护程序 ()、Docker 客户端 ()、Docker Compose、Docker Content Trust、Kubernetes 和 Credential Helper。有关更多信息,请参阅 Docker 桌面。dockerddocker

码头工人注册表

Docker 注册表存储 Docker 映像。Docker Hub 是公共的 任何人都可以使用的注册表,并且 Docker 配置为在 默认情况下为 Docker Hub。您甚至可以运行自己的私有注册表。

使用 or 命令时,所需的图像是 从配置的注册表中提取。使用该命令时, 映像将推送到配置的注册表。docker pulldocker rundocker push

码头工人对象

当您使用 Docker 时,您正在创建和使用映像、容器、网络、 卷、插件和其他对象。本节简要概述了一些 这些对象。

图像

映像是只读模板,其中包含有关创建 Docker 的说明 容器。通常,一个图像基于另一个图像,还有一些额外的 定制。例如,您可以构建一个基于该映像的映像,但会安装 Apache Web 服务器和您的应用程序,以及 使应用程序运行所需的配置详细信息。ubuntu

您可以创建自己的图像,也可以仅使用其他人创建的图像 并在注册表中发布。若要生成自己的映像,请使用简单的语法创建一个 Dockerfile,用于定义创建映像和运行所需的步骤 它。Dockerfile 中的每个指令都会在映像中创建一个图层。当你 更改 Dockerfile 并重建映像,仅更改那些具有 更改后重建。这是使图像如此轻巧,小巧, 与其他虚拟化技术相比,速度更快。

器皿

容器是映像的可运行实例。您可以创建、启动、停止、 使用 Docker API 或 CLI 移动或删除容器。您可以连接一个 容器到一个或多个网络,将存储附加到其中,甚至创建新的 基于其当前状态的图像。

默认情况下,容器与其他容器的隔离相对较好,并且 它的主机。您可以控制容器的网络、存储、 或其他底层子系统来自其他容器或主机 机器。

容器由其映像以及任何配置选项定义 在创建或启动它时提供它。删除容器后,对 未存储在持久存储中的状态将消失。

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2023-02-28,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 文章目录
  • docker是什么?
    • Docker Engine overview
    • 概述
      • 什么是容器container?
        • 什么是容器映像 image?
        • 官方解释什么是container和container image
          • Docker objects
            • Images - 一个用来创建docker容器的东西-----------类
              • Containers------实例(被用image创建的)
              • 码头工人架构
                • 码头工人守护进程The Docker daemon
                  • 码头工人客户端
                    • 码头工人桌面
                      • 码头工人注册表
                        • 码头工人对象
                          • 图像
                            • 器皿
                            相关产品与服务
                            容器服务
                            腾讯云容器服务(Tencent Kubernetes Engine, TKE)基于原生 kubernetes 提供以容器为核心的、高度可扩展的高性能容器管理服务,覆盖 Serverless、边缘计算、分布式云等多种业务部署场景,业内首创单个集群兼容多种计算节点的容器资源管理模式。同时产品作为云原生 Finops 领先布道者,主导开源项目Crane,全面助力客户实现资源优化、成本控制。
                            领券
                            问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档