谈谈那些欠下的技术债——Docker

Docker

什么是Docker?

  • 容器:Docker 容器(Container) 是从镜像创建的运行时实例。它是一个轻量级、独立的环境,可以在多个环境中一致运行,并且彼此隔离。
  • 镜像:容器的模板,包含运行应用程序所需的所有文件、依赖和配置。
  • Dockerfile:用于定义如何构建 Docker 镜像的脚本。
  • Docker Hub:Docker 镜像的公共仓库,可以下载和分享镜像。
Docker架构
  • Docker Client(客户端) :用户交互入口。

  • Docker Daemon(守护进程) :负责处理 Docker 容器、镜像、网络等操作的后台服务。

  • Docker Image(镜像) :创建容器的模板。

  • Docker Container(容器) :镜像的运行实例。

  • Docker 注册表:存储和分发镜像的地方。

  • Docker 网络:容器间的通信。

  • Docker 存储:持久化容器数据。

  • Docker Swarm:容器编排和集群管理工具。

    万字详解Docker架构原理、功能及使用-腾讯云开发者社区-腾讯云

Docker的运行流程
  1. 用户使用 Docker Client 与 Docker Daemon 建立通信,并发送请求给后者;

  2. Docker Daemon 作为 Docker 架构的主体部分,首先提供 Docker Server 的功能,使其可以接收 Docker Client 的请求;

  3. Docker Engine 执行 Docker 内部的一系列工作,每一项工作都是以一个 Job 的形式存在;

  4. Job 的运行过程中,当需要容器镜像时,则从 Docker Registry 中下载镜像,并通过镜像管理驱动 Graph Driver 将下载镜像以 Graph 的形式存储;

  5. 当需要为 Docker 创建网络环境时,通过网络管理驱动 Network driver 创建并配置 Docker 容器网络环境;

  6. 当需要限制 Docker 容器运行资源,或执行用户指令等操作时,则通过 Exec driver 来完成。

    Docker面试题及答案(99%面试官必问必考) – mikechen

容器的隔离是如何实现的?

Docker 通过多种技术实现了容器的隔离,确保容器在共享宿主机资源的同时,互相之间和宿主机之间没有干扰。通过 命名空间控制组文件系统隔离网络隔离安全机制等技术,Docker 能够提供强大的容器隔离性,使得容器化应用在执行时更加安全、独立和高效。

安装

下载地址:Docker: Accelerated Container Application Development

设置镜像源(Settings \ Docker Engine):

 
  

json

代码解读

复制代码

{ "registry-mirrors": [ "http://hub-mirror.c.163.com", "https://docker.mirrors.ustc.edu.cn" ], "insecure-registries": [], "debug": true, "experimental": false }

快速开始

Docker Hello World

cmd 打开并输入:

 
  

arduino

代码解读

复制代码

docker run hello-world

Unable to find image 'hello-world:latest' locally latest: Pulling from library/hello-world e6590344b1a5: Pull complete Digest: sha256:d715f14f9eca81473d9112df50457893aa4d099adeb4729f679006bf5ea12407 Status: Downloaded newer image for hello-world:latest

Hello from Docker! This message shows that your installation appears to be working correctly.

To generate this message, Docker took the following steps:

  1. The Docker client contacted the Docker daemon.
  2. The Docker daemon pulled the "hello-world" image from the Docker Hub. (amd64)
  3. The Docker daemon created a new container from that image which runs the executable that produces the output you are currently reading.
  4. The Docker daemon streamed that output to the Docker client, which sent it to your terminal.

To try something more ambitious, you can run an Ubuntu container with: $ docker run -it ubuntu bash

Share images, automate workflows, and more with a free Docker ID: hub.docker.com/

For more examples and ideas, visit: docs.docker.com/get-started…

Docker使用

全局命令
显示 Docker 系统的详细信息
 
  

代码解读

复制代码

docker info

显示 Docker 客户端和守护进程的版本信息
 
  

代码解读

复制代码

docker version

显示容器的实时资源使用情况
 
  

代码解读

复制代码

docker stats

清理不再使用的资源

删除停止的容器、未使用的网络和悬挂的镜像

 
  

css

代码解读

复制代码

docker system prune [OPTIONS]

强制清理

 
   

perl

代码解读

复制代码

docker system prune -f

包括卷在内的完全清理

 
   

css

代码解读

复制代码

docker system prune -a --volumes
容器使用
启动容器
 
  

arduino

代码解读

复制代码

dock

你可能感兴趣的:(docker,eureka,容器)