root环境下进行
卸载docker
# 删除docker及安装时自动安装的所有包
apt-get autoremove docker docker-ce docker-engine docker.io containerd runc
# 查看docker是否卸载干净
dpkg -l | grep docker
# 删除相关的配置文件及插件
dpkg -l |grep ^rc|awk '{print $2}' |sudo xargs dpkg -P
apt-get autoremove docker-ce-*
rm -rf /etc/systemd/system/docker.service.d
rm -rf /var/lib/docker
# 检查是否卸载完毕
docker --version
配置docker环境
1.更新软件包
apt update
apt upgrade
2.安装依赖包
apt-get install ca-certificates curl gnupg lsb-release
3.添加GPG密钥
curl -fsSL http://mirrors.aliyun.com/docker-ce/linux/ubuntu/gpg | sudo apt-key add -
4.添加docker软件源
add-apt-repository "deb [arch=amd64] http://mirrors.aliyun.com/docker-ce/linux/ubuntu $(lsb_release -cs) stable"
安装docker
1.
apt-get install docker-ce docker-ce-cli containerd.io
2.
usermod -aG docker $USER
3
systemctl start docker
4.
apt-get -y install apt-transport-https ca-certificates curl software-properties-common
5.
service docker restart
验证是否安装成功以及相关配置
docker run hello-world
查看下载的镜像
docker images
查看版本
docker version
换源
vi /etc/docker/daemon.json
#写入以下内容{ "registry-mirrors": [ "https://registry.docker-cn.com", "http://hub-mirror.c.163.com", "https://docker.mirrors.ustc.edu.cn", "https://kfwkfulq.mirror.aliyuncs.com" ] }
-------------------------------------------------
#重启docker
systemctl daemon-reload
systemctl restart docker
安装docker-compose
curl -L https://github.com/docker/compose/releases/download/v2.21.0/docker-compose-`uname -s`-`uname -m` -o /usr/local/bin/docker-compose
chmod +x /usr/local/bin/docker-compose
docker compose version