ubuntu系统安装指定版本的docker方法,本人亲自测试过

1.系统优化基础操作

hostnamectl set-hostname  master && bash
sudo systemctl stop ufw
sudo systemctl disable ufw
sudo apt update
sudo apt-get  -y upgrade

问题处理:

root@master:~# sudo apt-get  -y upgrade #执行这条语句,这里报错
E: Could not get lock /var/lib/dpkg/lock-frontend. It is held by process 2939 (unattended-upgr)
N: Be aware that removing the lock file is not a solution and may break your system.
E: Unable to acquire the dpkg frontend lock (/var/lib/dpkg/lock-frontend), is another process using it?
root@master:~# 

解决方法:
sudo rm /var/lib/apt/lists/lock
sudo rm /var/cache/apt/archives/lock
sudo rm /var/lib/dpkg/lock*
sudo dpkg --configure -a
sudo apt update
sudo apt-get -y upgrade

2.卸载过去安装过 docker

sudo apt-get remove docker docker-engine docker.io containerd runc

3.安装docker依赖及其库

sudo apt-get install apt-transport-https ca-certificates curl gnupg2 software-properties-common #安装依赖

#信任 Docker 的 GPG 公钥并添加仓库
sudo mkdir -m 0755 -p /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
echo \
  "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://mirror.nju.edu.cn/docker-ce/linux/ubuntu \
  $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null

#安装指定版本  首选查看都有哪些版本可选
apt-cache madison docker-ce


4. 安装最新版docker

sudo apt-get update
sudo apt-get install docker-ce

5.安装指定版本的docker

apt-cache madison docker-ce #查询到可以安装的docker版本

# 以 5:20.10.24~3-0~ubuntu-kinetic 为例
VERSION_STRING=5:20.10.24~3-0~ubuntu-kinetic

sudo apt-get install docker-ce=$VERSION_STRING docker-ce-cli=$VERSION_STRING containerd.io docker-buildx-plugin docker-compose-plugin

docker --version

注意:ubuntu22以上不需要加速,docker做了优化是默认带加速的。

cat > /etc/docker/daemon.json <<EOF
{
    "oom-score-adjust": -1000,
    "log-driver": "json-file",
    "log-opts": {
    "max-size": "100m",
    "max-file": "3"
    },
    "max-concurrent-downloads": 10,
    "max-concurrent-uploads": 10,
    "insecure-registries": ["0.0.0.0/0"],
    "registry-mirrors": ["https://wbdhknhl.mirror.aliyuncs.com"],
    "storage-driver": "overlay2",
    "storage-opts": [
    "overlay2.override_kernel_check=true"
    ]
}
EOF

systemctl daemon-reload && systemctl restart docker && sudo systemctl enable  docker && systemctl status docker

你可能感兴趣的:(linux,docker容器相关,ubuntu,docker,linux)