614

Ubuntu中安装Docker-CE

适用于 Ubuntu 20.04 22.04

卸载原版本

安装docker-ce社区版前,先卸载docker-desktop等原有版本

apt remove docker-desktop

apt autoremove

安装依赖包

让apt支持https

apt install apt-transport-https ca-certificates curl software-properties-common

添加GPG公钥

添加Docker官方库的GPG公钥到系统中,可选择官方或阿里云镜像源

  • Docker官方 GPG key
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
  • 阿里云镜像源 GPG key
curl -fsSL https://mirrors.aliyun.com/docker-ce/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg

添加apt-get安装源

添加 apt-get 安装源,可选择官方源或阿里云镜像源

  • Docker官方源
echo "deb [arch=$(dpkg --print-architecture) 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
  • 阿里云镜像源
echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://mirrors.aliyun.com/docker-ce/linux/ubuntu $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null

执行安装

更新软件包列表

apt update

查看并确认docker-ce软件包的信息

apt-cache policy docker-ce

执行安装最新版本

apt install docker-ce

或,安装指定版本

apt install docker-ce=5:26.1.3-1~ubuntu.22.04~jammy

如果缺少 docker-ce-cli containerd.io 时,可单独安装

apt install docker-ce-cli containerd.io

运行启动

安装完成后,启动

systemctl start docker

添加用户组

如果用户执行docker指令时,提示没有权限

permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock: Get "http://%2Fvar%2Frun%2Fdocker.sock/v1.24/containers/json": dial unix /var/run/docker.sock: connect: permission denied

只需要将用户加入docker用户组即可

# 如果没有docker用户组,则先创建该用户组
groupadd docker

# 将用户加入docker用户组
gpasswd -a <your_user_name> docker

# 更新docker用户组
newgrp docker
文章作者:DOTATONG
发布日期:2023-11-08
# docker

评论

暂无

添加新评论