Debian 12 安装 Docker
目录
一、序言
二、更新
先更新软件源
apt update
apt upgrade -y
如果安装过 docker ,执行下方命令卸载旧的 docker
apt-get purge docker-ce
apt-get purge docker-ce-cli
apt-get purge containerd.io
检查是否卸载完毕
apt list --installed | grep docker
apt list --installed | grep containerd.io
删除残留文件
rm -rf /var/lib/docker
rm -rf /var/run/docker
rm -rf /etc/docker
rm -rf /run/docker.sock
rm -rf /var/lib/containerd
rm -rf /run/containerd
rm -rf /opt/containerd
三、安装
安装 docker
相关软件
apt install curl vim wget gnupg dpkg apt-transport-https lsb-release ca-certificates
安装GPG证书
curl -fsSL https://mirrors.aliyun.com/docker-ce/linux/ubuntu/gpg | sudo apt-key add -
设置镜像源
官方源
curl -sSL https://download.docker.com/linux/debian/gpg | gpg --dearmor > /usr/share/keyrings/docker-ce.gpg echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-ce.gpg] https://download.docker.com/linux/debian $(lsb_release -sc) stable" > /etc/apt/sources.list.d/docker.list
清华 TUNA 的国内源
curl -sS https://download.docker.com/linux/debian/gpg | gpg --dearmor > /usr/share/keyrings/docker-ce.gpg echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-ce.gpg] https://mirrors.tuna.tsinghua.edu.cn/docker-ce/linux/debian $(lsb_release -sc) stable" > /etc/apt/sources.list.d/docker.list
阿里云镜像源
curl -sSL https://download.docker.com/linux/debian/gpg | gpg --dearmor > /usr/share/keyrings/docker-ce.gpg echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-ce.gpg] https://mirrors.aliyun.com/docker-ce/linux/debian $(lsb_release -sc) stable" > /etc/apt/sources.list.d/docker.list
安装 Docker CE
apt update
apt install docker-ce docker-ce-cli containerd.io docker-compose-plugin
安装完成后可以使用 docker version
命令检查 docker
是否安装成功,可以使用 docker compose version
检查 docker-compose
是否安装成功
四、配置
以下配置会增加一段自定义内网 IPv6 地址,开启容器的 IPv6 功能,以及限制日志文件大小,防止 Docker 日志塞满硬盘 (泪的教训)
cat > /etc/docker/daemon.json << EOF
{
"log-driver": "json-file",
"log-opts": {
"max-size": "20m",
"max-file": "3"
},
"ipv6": true,
"fixed-cidr-v6": "fd00:dead:beef:c0::/80",
"experimental":true,
"ip6tables":true
}
EOF
重启 Docker 服务
systemctl restart docker