01 - 安装docker
0、如果你过去安装过 docker,先删掉
sudo apt-get remove docker docker-engine docker.io containerd runc
sudo apt-get purge docker-ce docker-ce-cli containerd.io
sudo rm -rf /var/lib/docker
sudo rm -rf /etc/docker
sudo rm -rf /var/run/docker.sock
sudo rm -rf /var/run/docker.pid
1、更新软件源列表
sudo apt update
2.安装软件包依赖
ssudo apt install -y apt-transport-https ca-certificates curl gnupg2 software-properties-common
3.在系统中添加Docker的官方密钥
Debian
curl -fsSL https://download.docker.com/linux/debian/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
Ubuntu
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
4.添加软件仓库
Debian
echo \
"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://mirrors.tuna.tsinghua.edu.cn/docker-ce/linux/debian \
$(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
Ubuntu
echo \
"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://mirrors.tuna.tsinghua.edu.cn/docker-ce/linux/ubuntu \
$(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
5.开始安装Docker(ce表示社区版)
sudo apt update
sudo apt install -y docker-ce
6.查看安装的Docker版本
docker -v
7.启动Docker服务
sudo systemctl start docker
8.设置开机自启动docker
sudo systemctl enable docker
9.查看Docker是否开启,出现绿色圆点表示服务正常开启
sudo systemctl status docker
02 - Docker 镜像源配置
1、修改配置文件
nano /etc/docker/daemon.json
2、按照以下信息配置
{
"registry-mirrors" : [
"https://registry.docker-cn.com",
"http://hub-mirror.c.163.com",
"https://docker.mirrors.ustc.edu.cn",
"https://cr.console.aliyun.com",
"https://mirror.ccs.tencentyun.com"
]
}
3、重启 Docker 服务
sudo systemctl daemon-reload
sudo systemctl restart docker
03 - 安装Docker-compose
curl -SL https://github.com/docker/compose/releases/download/v2.18.1/docker-compose-linux-x86_64 -o /usr/local/bin/docker-compose
chmod +x /usr/local/bin/docker-compose
下一步不是必须的
sudo ln -s /usr/local/bin/docker-compose /usr/bin/docker-compose
验证是否成功
docker-compose --version