目录
5、删除docker的镜像文件,默认在/var/lib/docker目录下
Docker 两个主要部件:
镜像是Docker的基本构建块,是一个只读的模板,包含了运行环境、文件系统、应用程序和依赖等。镜像可以用来创建容器,一个镜像可以被多个容器同时使用。
仓库是用来存储和分享镜像的地方,它可以分为本地仓库和远程仓库两种类型。本地仓库存储在本地机器上,而远程仓库则可以通过网络访问。仓库中的每个镜像都有一个唯一的标识符,称为镜像标签(Image Tag),可以用来唯一标识和区分不同的镜像版本。
容器是基于镜像创建的一个可运行的实例,它是一个独立且隔离的运行环境。容器可以被快速创建、启动、停止、删除,并且具有轻量级、可移植性和可复用性等特点。
这三个要素共同构成了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来完成。
7、Libcontainer是一项独立的容器管理包,Network driver以及Exec driver都是通过Libcontainer来实现具体对容器进行的操作
使用yum安装docker 如需卸载docker可以按下面步骤操作:
systemctl stop docker
- [root@localhost ~]# yum list installed |grep docker
- Repodata is over 2 weeks old. Install yum-cron? Or run: yum makecache fast
- containerd.io.x86_64 1.6.22-3.1.el7 @docker-ce-stable
- docker-buildx-plugin.x86_64 0.11.2-1.el7 @docker-ce-stable
- docker-ce.x86_64 3:24.0.6-1.el7 @docker-ce-stable
- docker-ce-cli.x86_64 1:24.0.6-1.el7 @docker-ce-stable
- docker-ce-rootless-extras.x86_64 24.0.6-1.el7 @docker-ce-stable
- docker-compose-plugin.x86_64 2.21.0-1.el7 @docker-ce-stable
-
- 有一个报错,我们直接运行
- [root@localhost ~]# yum makecache fast
- Loaded plugins: fastestmirror, langpacks
- base
- [root@localhost ~]# rpm -qa |grep docker
- docker-ce-cli-24.0.6-1.el7.x86_64
- docker-ce-24.0.6-1.el7.x86_64
- docker-buildx-plugin-0.11.2-1.el7.x86_64
- docker-compose-plugin-2.21.0-1.el7.x86_64
- docker-ce-rootless-extras-24.0.6-1.el7.x86_64
[root@localhost ~]# yum -y remove containerd.io.x86_64 docker-buildx-plugin.x86_64 docker-ce.x86_64 docker-ce-cli.x86_64 docker-ce-rootless-extras.x86_64 docker-compose-plugin.x86_64
- [root@localhost lib]# rm -rf /var/lib/docker
- [root@localhost lib]# rm -rf /var/lib/containerd
到此docker卸载就完成了
官网:https://docs.docker.com/engine/install/centos/
- 1、下载Docker依赖组件
- [root@localhost lib]# yum -y install yum-utils device-mapper-persistent-datalvm2
- Loaded plugins: fastestmirror, langpacks
- Loading mirror speeds from cached hostfile
- * base: mirrors.jlu.edu.cn
- * epel: ftp.kaist.ac.kr
- * extras: mirrors.aliyun.com
- * updates: mirrors.aliyun.com
- Package yum-utils-1.1.31-54.el7_8.noarch already installed and latest version
- No package device-mapper-persistent-datalvm2 available.
- Nothing to do
-
- 2、安装gcc gcc-c++ 相关依赖
- 3、设置下载Docker的镜像源为阿里云
- [root@localhost lib]# yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
- Loaded plugins: fastestmirror, langpacks
- adding repo from: http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
- grabbing file http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo to /etc/yum.repos.d/docker-ce.repo
- repo saved to /etc/yum.repos.d/docker-ce.repo
- 4、更新yum软件包索引
- [root@localhost docker]# yum makecache fast
-
- 5、安装Docker服务
- [root@localhost lib]# yum -y install docker-ce docker-ce-cli containerd.io
-
- 6、设置开机自动启动
- [root@localhost lib]# systemctl enable docker
- 7、测试安装成功
- [root@localhost lib]# docker version
- 8、启动docker
- [root@localhost lib]# systemctl start docker
- 9、查看docker 运行状态
- [root@localhost lib]# systemctl status docker.service
-
- 10、测试docker
- [root@localhost lib]# docker run hello-world
- Unable to find image 'hello-world:latest' locally
- latest: Pulling from library/hello-world
- c1ec31eb5944: Pull complete
- Digest: sha256:266b191e926f65542fa8daaec01a192c4d292bff79426f47300a046e1bc576fd
- 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/
-
-
- [root@localhost lib]#
- 看到 Hello from Docker! 字段说明我们的安装步骤没有问题,Docker已经成功安装~
镜像地址通过阿里云官网查看
- 要配置Docker使用这些加速器,你可以编辑Docker的配置文件daemon.json(通常位于
- /etc/docker/),并添加registry-mirrors键值。以下是一个示例配置:
-
- [root@localhost docker]# tee /etc/docker/daemon.json <<-'EOF'
- > {
- > "registry-mirrors": ["https://t2exmlj4.mirror.aliyuncs.com"]
- > }
- > EOF
- {
- "registry-mirrors": ["https://t2exmlj4.mirror.aliyuncs.com"]
- }
- [root@localhost docker]#
- [root@localhost docker]#
- [root@localhost docker]# ll
- total 4
- -rw-r--r--. 1 root root 67 May 28 16:19 daemon.json
- [root@localhost docker]#
- [root@localhost docker]#
- [root@localhost docker]# cat daemon.json
- {
- "registry-mirrors": ["https://t2exmlj4.mirror.aliyuncs.com"]
- }
- [root@localhost docker]#
- [root@localhost docker]#
- [root@localhost docker]# systemctl daemon-reload
- [root@localhost docker]# systemctl restart docker
- [root@localhost docker]#
- [root@localhost docker]# systemctl status docker