赞
踩
首先在部署Docker环境前,得先了解Docker的引擎架构
docker daemon实现了docker api,对容器的操作由containerd完成,containerd需要指挥与OCI相兼容的容器运行时来创建容器,默认情况下,docker使用runc来作为其默认的容器运行时,containerd调用runc,并确保docker镜像以OCI bundle的格式传给runc。其中:
runc是OCI容器运行时标准的参考实现,runc实际上是一个轻量级的、针对libcontainer进行了包装的命令行交互工具。runc生来只有一个作用,创建容器。
containerd 的主要任务是容器的生命周期的管理,containerd在linux和windows中以daemon的方式运行,在docker引擎技术栈中,containerd位于daemon和runc所在的OCI层之间。
shim是实现无daemon的容器不可获取的工具,前面提到containerd指挥runc来创建容器,事实上,每次创建容器时都会fork(分叉出)一个新的runc实例,不过,一旦容器创建完毕,对应的runc进程就会退出,因此即使运行上百个容器,也无须保持上百个的runc处于运行状态。一旦容器进程的父进程runc退出,相关联的containerd-shim进程就会成为容器的父进程,作为容器的父进程,shim的部分职责如下:
[root@server ~]# docker container run --name ctrl -it alpine:latest sh
这里我们通过yum源来安装Docker
系统基础环境
查询自己服务器的环境
[root@server ~]# cat /etc/redhat-release
Red Hat Enterprise Linux release 9.1 (Plow)
内核版本
[root@server ~]# uname -r
5.14.0-162.6.1.el9_1.x86_64
IP地址
[root@server ~]# hostname -I #列出主机的所有IP地址
192.168.80.129
[root@server ~]# hostname -i #列出主机的IP地址
fe80::20c:29ff:fe9e:1d25%ens160 192.168.80.129
是一个提供yum-config-manager命令的工具包
[root@server ~]# yum install yum-utils -y
在阿里云镜像站中找的这个docker-ce.repo包,鼠标右击复制链接
[root@server ~]# yum-config-manager --add-repo https://mirrors.aliyun.com/docker-ce/linux/rhel/docker-ce.repo
[root@server ~]# cd /etc/yum.repos.d/
[root@server yum.repos.d]# ll
总用量 12
-rw-r--r-- 1 root root 2045 3月 23 16:35 docker-ce.repo #就出现了这个文件
-rw-r--r--. 1 root root 358 11月 11 19:28 redhat.repo
-rw-r--r--. 1 root root 223 11月 11 19:25 RHELserver.repo
[root@server ~]# yum install docker-ce -y
多种加速方式:
Docker拉取镜像的过程涉及多个步骤,以下是其详细的流程:
1.配置国内Docker的下载源:
2.执行拉取命令:
3.Docker Hub查找镜像:
4.下载镜像:
5.验证和存储镜像:
6.使用镜像:
通过以上步骤,你就可以成功地从Docker Hub或其他配置的镜像源拉取所需的镜像,并在本地创建和运行容器。
配置阿里云镜像仓库地址
[root@server ~]# vim /etc/docker/daemon.json
{
"registry-mirrors": ["https://0wfqs2it.mirror.aliyuncs.com"]
}
[root@server ~]# systemctl daemon-reload
[root@server ~]# systemctl restart docker
[root@server ~]# docker run hello-world 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/
[root@server ~]# docker container run hello-world #新写法 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/
[root@server ~]# docker images #查看拉取的镜像
REPOSITORY TAG IMAGE ID CREATED SIZE
hello-world latest d2c94e258dcb 10 months ago 13.3kB
至此,Docker已经安装配置成功,可以在RHEL9上愉快使用啦~
[root@server ~]# docker version Client: Docker Engine - Community Version: 26.0.0 API version: 1.45 Go version: go1.21.8 Git commit: 2ae903e Built: Wed Mar 20 15:19:53 2024 OS/Arch: linux/amd64 Context: default Server: Docker Engine - Community Engine: Version: 26.0.0 API version: 1.45 (minimum version 1.24) Go version: go1.21.8 Git commit: 8b79278 Built: Wed Mar 20 15:18:08 2024 OS/Arch: linux/amd64 Experimental: false containerd: Version: 1.6.28 GitCommit: ae07eda36dd25f8a1b98dfbf587313b99c0190bb runc: Version: 1.1.12 GitCommit: v1.1.12-0-g51d5e94 docker-init: Version: 0.19.0 GitCommit: de40ad0 [root@server ~]#
[root@server ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
e587adbe6c82 mysql "docker-entrypoint.s…" 3 minutes ago Up 3 minutes 3306/tcp, 33060/tcp mysql13
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。