在 ubuntu 上安装 docker 和 docker-compose ,经常会用到,但一直没有编排好;这次作一个记录;
- 升级 apt
sudo apt update
1
- 卸载
docker
(如果有)
$ sudo apt-get remove docker docker-engine docker.io containerd runc
1
- 更新依赖
$ sudo apt-get install \
apt-transport-https \
ca-certificates \
curl \
gnupg \
lsb-release
1
2
3
4
5
6
2
3
4
5
6
- 添加Docker官方的GPG密钥:
$ curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
1
- Docker存储库添加到APT源命令:
$ echo \
"deb [arch=amd64 signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu \
$(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
1
2
3
2
3
- 安装 docker
$ sudo apt-get update
$ sudo apt-get install docker-ce docker-ce-cli containerd.io
1
2
2
Tips
可以通过 docker -v
验证是否安装成功!
- 启动
docker
服务
$ sudo systemctl start docker
1
- 通过 github (opens new window) 上的发行版列表,找到自己喜欢的版本,并记录下 版本号
- 下载
docker-compose
$ sudo curl -L https://github.com/docker/compose/releases/download/1.29.2/docker-compose-`uname -s`-`uname -m` -o /usr/local/bin/docker-compose
1
Tips
简单解释下命令:下载 docker-compose-Linux-x86_64
文件,并保存到 /usr/local/bin/
路径下,并重命名为 docker-compose
- 为
docker-compose
授权执行权限
$ chmod +x /usr/local/bin/docker-compose
1
- 验证安装
$ docker-compose version
1
问题一览
- GPG报错 GPG error: https://download.docker.com/linux/ubuntu bionic InRelease: The following signatures couldn't be verified because the public key is not available: NO_PUBKEY 7EA0A9C3F273FCD8
解决方案:
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 425956BB3E31DF51
1
- 查看cpu架构
解决方案:
$ lscpu
Architecture: x86_64 ##cpu架构
1
2
2
参考一览