docker容器本质&安装&卸载

docker简述

                            (个人简单理解)

1.容器技术并不是 Docker 公司的技术,而是 Linux 内核的技术
2.目前赤手可热的容器技术的核心功能,就是通过约束和修改进程的动态表现,从而为其创造出一个“边界”
3.对于 Docker 等大多数 Linux 容器来说,Cgroups 技术是用来制造约束的主要手段,而 Namespace 技术则是用来修改进程视图的主要方法

Namespace 名称空间隔离

Namespace名称空间隔离:名称空间用于对进程直接的隔离,就是保证进程只能看到我们规定好的那些资源
1.为了能够让容器的这个根目录看起来更“真实”,我们一般会在这个容器的根目录下挂载一个完整操作系统的文件系统,比如 Centos7 的 目录结构。这样,在容器启动之后,我们在容器里通过执行 “ls /” 查看根目录下的内容,就是 Centos7 的所有目录和文件
2.Namespace 技术实际上修改了应用进程看待整个计算机“视图”,即它的“视线”被操作系统做了限制,只能“看到”某些指定的内容。但对于宿主机来说,这些被“隔离”了的进程跟其他进程并没有太大区别
3.这个挂载在容器根目录上、用来为容器进程提供隔离后执行环境的文件系统,就是所谓的“容器镜像”。它还有一个更为专业的名字,叫作:rootfs(根文件系统)

注意: 在 Linux 内核中,有很多资源和对象是不能被 Namespace 化的,最典型的例子就是:时间。

Cgroups 资源限制

1.Linux Cgroups 就是 Linux 内核中用来为进程设置资源限制的一个重要功能
2.Linux Cgroups 的全称是 Linux Control Group。它最主要的作用,就是限制一个进程组能够使用的资源上限,包括 CPU、内存、磁盘、网络带宽等等
3.Cgroups 还能够对进程进行优先级设置、审计,以及将进程挂起和恢复等操作
4.在 Linux 中,Cgroups 给用户暴露出来的操作接口是文件系统,即它以文件和目录的方式组织在操作系统的 /sys/fs/cgroup 路径下

docker安装

1.下载docker仓库

[root@localhost ~]# wget https://download.docker.com/linux/centos/docker-ce.repo -O /etc/yum.repos.d/docker-ce.repo

2.安装docker引擎

[root@localhost ~]# yum install -y docker-ce docker-ce-cli containerd.io

3.启动docker

[root@localhost ~]# systemctl start docker && systemctl enable docker

4.通过运行hello-world 映像来验证是否正确安装了Docker Engine

[root@localhost ~]# docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
b8dfde127a29: Pull complete 
Digest: sha256:308866a43596e83578c7dfa15e27a73011bdd402185a84c5cd7f32a88b501a24
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:
 https://hub.docker.com/

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

5.使用阿里云的镜像源,加速镜像下载速度

进入阿里云控制台,选择容器镜像服务,点击镜像加速,按照提示配置加速,然后重启docker服务
(注意!每个人的加速地址不同)

6.运行docker

[root@localhost ~]# docker run  -it   centos:7
                       #子命令,选项,镜像名称:标签 
[root@localhost ~]# docker run -it --name  wangwang centos:7
                                    # 指定容器名
[root@2b03e5f9610a /]# exit
exit
#退出docker

-t 分配一个伪TTY,以便和容器进行命令的交互
-i 表示持续和 容器交互,防止断开

docker卸载

1.卸载Docker Engine,CLI和Containerd软件包

[root@localhost ~]# yum remove docker-ce docker-ce-cli containerd.io
已加载插件:fastestmirror
正在解决依赖关系
--> 正在检查事务
---> 软件包 containerd.io.x86_64.0.1.4.4-3.1.el7 将被 删除
---> 软件包 docker-ce.x86_64.3.20.10.5-3.el7 将被 删除
--> 正在处理依赖关系 docker-ce,它被软件包 docker-ce-rootless-extras-20.10.5-3.el7.x86_64 需要
---> 软件包 docker-ce-cli.x86_64.1.20.10.5-3.el7 将被 删除
--> 正在检查事务
---> 软件包 docker-ce-rootless-extras.x86_64.0.20.10.5-3.el7 将被 删除
--> 解决依赖关系完成
#略

2. 删除所有的镜像、容器和卷

[root@bogon ~]# rm -rf /var/lib/docker
  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值