Ubuntu安装docker及docker-compose

一、安装docker

1.在终端输入

apt update
apt-get install ca-certificates curl gnupg lsb-release

2.安装证书

curl -fsSL http://mirrors.aliyun.com/docker-ce/linux/ubuntu/gpg | sudo apt-key add -

3.写入软件源信息

sudo add-apt-repository "deb [arch=amd64] http://mirrors.aliyun.com/docker-ce/linux/ubuntu $(lsb_release -cs) stable"

4.安装docker

sudo apt-get install docker-ce docker-ce-cli containerd.io

前3步可能会出现些失败,但并不影响安装

5.启动docker验证一下

systemctl start docker
docker version

如果显示没有权限,按照如下授权并重启

sudo groupadd docker 2>/dev/null || true
newgrp docker
sudo usermod -aG docker $USER

echo sudo service docker start

再用docker version验证

Ubuntu安装docker及docker-compose_第1张图片

出现以上版本信息说明安装成功

二、安装docker-compose

安装docker-compose2.0

# setup repository
sudo apt-get update
sudo apt-get install -y \
    ca-certificates \
    curl \
    gnupg \
    lsb-release
sudo mkdir -p /etc/apt/keyrings
curl -fsSL https://mirrors.ustc.edu.cn/docker-ce/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
echo \
  "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://mirrors.ustc.edu.cn/docker-ce/linux/ubuntu \
  $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null

# install docker engine
sudo apt-get update
sudo apt-get install -y docker-ce docker-ce-cli containerd.io docker-compose-plugin

如果要卸载,使用以下命令

sudo apt-get remove docker docker-engine docker.io containerd runc

你可能感兴趣的:(日常解决小问题,docker,ubuntu,运维,1024程序员节)