1.更新软件源列表
sudo apt update
2.安装软件包依赖
sudo apt install apt-transport-https ca-certificates curl software-properties-common
3.在系统中添加Docker的官方密钥
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
4.添加Docker源,选择stable长期稳定版
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu bionic stable"
5.再次更新源列表
sudo apt update
6.查看可以安装的Docker版本
sudo apt-cache policy docker-ce
7.开始安装Docker
这里以20.10版本为例
sudo apt-get install -y docker-ce=5:20.10.10~3-0~ubuntu-bionic docker-ce-cli=5:20.10.10~3-0~ubuntu-bionic containerd.io
9.查看安装的Docker版本
10.启动Docker服务
sudo systemctl start docker
11.设置开机自启动docker
sudo systemctl enable docker
sudo systemctl start docker
sudo systemctl enable docker
sudo systemctl status docker
sudo mkdir -p /etc/docker
sudo tee /etc/docker/daemon.json <<-'EOF'
{
"registry-mirrors": ["https://docker.mirrors.ustc.edu.cn"],
"exec-opts": ["native.cgroupdriver=systemd"],
"log-driver": "json-file",
"log-opts": {
"max-size": "100m"
},
"storage-driver": "overlay2"
}
EOF
sudo systemctl daemon-reload
sudo systemctl restart docker
查看是否配置成功
docker info
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
sudo chmod +x /usr/local/bin/docker-compose
docker-compose --version
Ubuntu18.04安装Docker完整教程_ubuntu 18 安装 docker-CSDN博客