debian10安装docker和docker-compose
首先安装docker
一、环境
系统:debian10.11.0
docker版本:20.10.5
docker-compose版本:2.2.2
服务器地址 192.168.2.204
配置时间同步
# 添加sbin命令
export PATH=$PATH:/usr/sbin
# 写出时间同步配置文件
echo [Time]>/etc/systemd/timesyncd.conf
echo NTP=ntp1.aliyun.com ntp2.aliyun.com time1.cloud.tencent.com time2.cloud.tencent.com>>/etc/systemd/timesyncd.conf
# 重启时间同步服务
systemctl restart systemd-timesyncd
# 查看时间同步状态
timedatectl timesync-status
# 查看运行状态
systemctl status systemd-timesyncd
时间同步服务状态正常
配置阿里源
# 备份apt源配置
cp /etc/apt/sources.list /etc/apt/sources.list.bak
# 删除apt源配置
rm -rf /etc/apt/sources.list
# 写出阿里apt源配置
tee /etc/apt/sources.list <<-'EOF'
deb http://mirrors.aliyun.com/debian/ buster main non-free contrib
deb http://mirrors.aliyun.com/debian/ buster-updates main non-free contrib
deb http://mirrors.aliyun.com/debian/ buster-backports main non-free contrib
deb-src http://mirrors.aliyun.com/debian/ buster main non-free contrib
deb-src http://mirrors.aliyun.com/debian/ buster-updates main non-free contrib
deb-src http://mirrors.aliyun.com/debian/ buster-backports main non-free contrib
deb http://mirrors.aliyun.com/debian-security/ buster/updates main non-free contrib
deb-src http://mirrors.aliyun.com/debian-security/ buster/updates main non-free contrib
EOF
# 清理apt缓存
apt-get clean
# 更新apt缓存
apt-get update
创建目录,还有配置文件
# 创建docker目录
mkdir -p /etc/docker /opt/docker
# 创建docker配置文件
tee /etc/docker/daemon.json <<-'EOF'
{
"graph": "/opt/docker",
"log-driver": "json-file",
"log-opts": {
"max-size": "800m",
"max-file": "50"
},
"registry-mirrors": [
"https://hub-mirror.c.163.com",
"https://docker.mirrors.ustc.edu.cn",
"https://registry.docker-cn.com"
]
}
EOF
2.2 安装docker
安装工具依赖
aptitude install -y apt-transport-https ca-certificates curl gnupg2 software-properties-common #我采用的是aptitude可以解决依赖关系
安装GPG证书
curl -fsSL https://mirrors.aliyun.com/docker-ce/linux/debian/gpg | apt-key add -
添加软件源
add-apt-repository "deb [arch=amd64] https://mirrors.aliyun.com/docker-ce/linux/debian $(lsb_release -cs) stable"
更新缓存
apt-get update
安装docker
aptitude install -y docker-ce docker-ce-cli containerd.io
下载docker-compose
# 下载docker-compose
curl -L "https://github.com/docker/compose/releases/download/v2.2.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
这里地方出现报错,是因为是githup上面的,容易连接不到,多尝试几次
我这里就采用科学上网的方式,去下载如果公司有规定,建议不要模仿
# 给予docker-compose执行权
chmod +x /usr/local/bin/docker-compose
# 重载systemctl配置文件
systemctl daemon-reload
# 重启docker
systemctl restart docker
# docker开机自动启动
systemctl enable docker.service
# containerd容器开机自动启动
systemctl enable containerd.service
# 查看docker版本信息
docker info
# 查看docker-compose版本信息
docker-compose --version
查看版本
遇到报错内容
docker-compose版本信息
docker-compose --version
[外链图片转存中...(img-DxxkDQjE-1657791424621)]
查看版本
[外链图片转存中...(img-iDn8iD4s-1657791424621)]
###### 遇到报错内容
![image-20220705192522314](https://img-blog.csdnimg.cn/img_convert/62225bb7d329845d7265c8f47206683d.png)