docker在linux下的安装

Docker 安装步骤 (Ubuntu)

  • Step 1: 更新系统软件包
sudo apt update
  • Step 2: 安装依赖包【用于通过HTTPS来获取仓库】
sudo apt install apt-transport-https ca-certificates curl software-properties-common
  • Step 3: 添加 Docker 官方 GPG 密钥
    curl 是一个用于在命令行中传输数据的工具,支持多种协议,包括 HTTP、HTTPS、FTP 等
    但是其在root下的运行很奇怪
sudo -i #用来在终端中以 root 用户的身份启动一个新的登录 shell
curl -fsSL https://mirrors.aliyun.com/docker-ce/linux/ubuntu/gpg | gpg --dearmor -o /etc/apt/trusted.gpg.d/docker-ce.gpg
  • Step 4: 验证 GPG 密钥
sudo apt-key fingerprint 0EBFCD88
  • Step 5: 添加 Docker 阿里稳定版软件源
sudo add-apt-repository "deb [arch=amd64] https://mirrors.aliyun.com/docker-ce/linux/ubuntu $(lsb_release -cs) stable"
  • Step 6: 再次更新软件包
sudo apt update
  • Step 7: 安装 Docker
sudo apt install docker-ce docker-ce-cli containerd.io
  • Step 8: 测试 Docker 安装
sudo docker run hello-world
  • Step 9: 查看已下载的镜像
sudo docker images
  • Step 10: 配置用户组
sudo usermod -aG docker galaxfy
su - galaxfy  # 刷新shell状态
docker images # 验证用户组配置

其他 Docker 运行命令:

  • 查看 Docker 状态
sudo systemctl status docker
  • 启动 Docker
sudo systemctl start docker
  • 设置 Docker 开机自启
sudo systemctl enable docker
  • 停止 Docker 服务
sudo systemctl stop docker
  • 安装特定版本的 Docker
sudo apt-cache madison docker-ce  # 显示可用版本
sudo apt-get install docker-ce=<VERSION_STRING> docker-ce-cli=<VERSION_STRING> containerd.io # 将需要的版本替换 VERSION_STRING 进行安装, 例如 5:20.10.17~3-0~ubuntu-focal
posted @ 2024-09-08 22:15  skybase  阅读(150)  评论(0)    收藏  举报