1. 安装docker环境
1.1 查看系统环境
[root@AlmaLinux-9 ~]$ cat /etc/redhat-release ; uname -rs
移除旧版本的Docker(如果有):
sudo yum remove docker \
docker-client \
docker-client-latest \
docker-common \
docker-latest \
docker-latest-logrotate \
docker-logrotate \
docker-engine
1.2 安装docker引擎
要使用docker,必须先安装docker引擎,步骤如下:
# 安装Docker的依赖包:
[root@AlmaLinux-9 ~]$ yum install -y yum-utils device-mapper-persistent-data lvm2 dnf-plugins-core
# 设置Docker的官方仓库:
[root@AlmaLinux-9 ~]$ yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
# 安装Docker
[root@AlmaLinux-9 ~]$ yum install -y docker-ce docker-ce-cli containerd.io
1.3 启动docker服务
启动Docker服务并设置开机自启并验证Docker是否正确安装:
[root@AlmaLinux-9 ~]$ systemctl enable docker --now
[root@AlmaLinux-9 ~]$ docker run hello-world
1.4 添加docker加速地址
-
由于受docker受国内影响,国内很多加速地址都下架了,目前还能使用的加速地址包括:
-
支持系统:Ubuntu 16.04+、Debian 8+、CentOS 7+:
sudo mkdir -p /etc/docker
sudo tee /etc/docker/daemon.json <<EOF
{
"registry-mirrors": [
"https://hub.uuuadc.top",
"https://docker.anyhub.us.kg",
"https://dockerhub.jobcher.com",
"https://dockerhub.icu",
"https://docker.ckyl.me",
"https://docker.awsl9527.cn"
]
}
EOF
# 重启生效
sudo systemctl daemon-reload
sudo systemctl restart docker
1.5 查看docker版本
[root@AlmaLinux-9 ~]$ docker version
Client: Docker Engine - Community
Version: 27.1.2
API version: 1.46
Go version: go1.21.13
Git commit: d01f264
Built: Mon Aug 12 11:52:33 2024
OS/Arch: linux/amd64
Context: default
Server: Docker Engine - Community
Engine:
Version: 27.1.2
API version: 1.46 (minimum version 1.24)
Go version: go1.21.13
Git commit: f9522e5
Built: Mon Aug 12 11:50:54 2024
OS/Arch: linux/amd64
Experimental: false
containerd:
Version: 1.7.20
GitCommit: 8fc6bcff51318944179630522a095cc9dbf9f353
runc:
Version: 1.1.13
GitCommit: v1.1.13-0-g58aa920
docker-init:
Version: 0.19.0
GitCommit: de40ad0
1.6 拉取镜像
拉取镜像并启动容器:
[root@AlmaLinux-9 ~]$ docker pull centos
[root@AlmaLinux-9 ~]$ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
centos latest 5d0da3dc9764 2 years ago 231MB
[root@AlmaLinux-9 ~]$ docker run -d -it centos
标签:Version,AlmaLinux,release,version,9.4,docker,root,Docker
From: https://www.cnblogs.com/Xneat/p/18369180