一键安装docker
shell
# 自动识别系统并且安装docker
curl -fsSL https://get.docker.com -o get-docker.sh
# 运行脚本
sh ./get-docker.sh
# 启动docker并设为开机自启
systemctl start docker && systemctl enable docker
# 设置docker国内镜像源
cat <<EOF>> /etc/docker/daemon.json
{
"registry-mirrors": [
"http://hub-mirror.c.163.com",
"https://docker.mirrors.ustc.edu.cn",
"https://registry.docker-cn.com"
]
}
EOF
# 重启docker
systemctl daemon-reload && systemctl restart docker
# 检查docker
docker version
# 下载docker-compose
wget https://github.com/docker/compose/releases/download/v2.11.2/docker-compose-linux-x86_64 -O /usr/local/bin/docker-compose && chmod +x /usr/local/bin/docker-compose
# 检查docker-compose
docker-compose version
Debian
安装docker
shell
# 安装必要的依赖项通过HTTPS添加新存储库
apt install -y apt-transport-https ca-certificates curl software-properties-common gnupg2
# 使用以下导入存储库的GPG密钥
curl -fsSL https://download.docker.com/linux/debian/gpg | sudo apt-key add -
# 将Docker APT存储库添加到系统的软件存储库列表中
add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/debian $(lsb_release -cs) stable"
# 安装docker ce最新版本
apt update
apt install -y docker-ce
# 检查docker运行状态以及版本
systemctl status docker
docker -v
安装docker-compose
shell
# 下载docker-compose
wget https://github.com/docker/compose/releases/download/v2.12.0/docker-compose-linux-x86_64 -O /usr/local/bin/docker-compose && chmod +x /usr/local/bin/docker-compose
# 检查docker-compose
docker-compose version
Rocky Linux
安装Docker
1. 把yum包更新到最新
shell
yum update -y
2. 安装需要的软件包
shell
yum install -y yum-utils device-mapper-persistent-data lvm2
3. 设置yum源
阿里云仓库
shell
yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
中央仓库
shell
yum-config-manager --add-repo http://download.docker.com/linux/centos/docker-ce.repo
4. 安装Docker
shell
# 如果要安装指定版本docker的话可以查询仓库有哪些版本(可选)
yum list docker-ce --showduplicates | sort -r
# 指定版本(可选)
yum install docker-ce-26.1.3-1.el9 docker-ce-cli-26.1.3-1.el9 containerd.io docker-buildx-plugin docker-compose-plugin-2.27.0-1.el9 -y
# 安装docker(不带版本号就是最新的)
yum install docker-ce -y
