Docker 入门教程之安装

作者: phpworkerman | 来源:发表于2021-08-06 22:45 被阅读0次

Docker 安装方式为三种,Windows、Mac 和 Linux

一、Windows
  • 准备 win10 系统

  • 开启 CPU 虚拟化,开启成功后,任务管理器-性能可以看到虚拟化已启用

    image.png
  • 安装 WSL2,并且更新 Linux 内核,此处参照微软 WSL2 安装文档

  • 官网下载页面 下载 windows 安装程序,安装很简单,打开 exe 文件,直接 OK 下一步即可

    image.png
  • 验证安装成功


    image.png
二、Linux
  • 支持的发行版和架构为 Centos、Ubuntu、Debian、Fedora、Raspbian(树莓派)、RHEL、SLES
  • 本教程以 Ubuntu 21.04 安装为例,版本需要大于等于 18.04
    首先卸载旧版本的 Docker
 sudo apt-get remove docker docker-engine docker.io containerd runc

通过安装 Docker 仓库源的方式进行安装,先更新 Ubuntu 系统的官方仓库源,安装必要的服务

# 更新官方源
sudo apt-get update
# 安装必要的服务
sudo apt-get install \
    apt-transport-https \
    ca-certificates \
    curl \
    gnupg \
    lsb-release

设置 Docker 官方的 GPG KEY

curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg

添加 Docker 官方仓库源

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

安装 Docker(最新版本)

# 更新 apt
sudo apt-get update
# 安装 Docker
sudo apt-get install docker-ce docker-ce-cli containerd.io

如果系统存在多个 Docker 仓库源,以上方法只会安装最新的 Docker 版本,对于想指定安装版本可以使用以下方法

安装 Docker(指定版本)

apt-cache madison docker-ce
# docker-ce | 5:20.10.8~3-0~ubuntu-hirsute | https://download.docker.com/linux/ubuntu hirsute/stable amd64 Packages
# docker-ce | 5:20.10.7~3-0~ubuntu-hirsute | https://download.docker.com/linux/ubuntu hirsute/stable amd64 Packages
# docker-ce | 5:20.10.6~3-0~ubuntu-hirsute | https://download.docker.com/linux/ubuntu hirsute/stable amd64 Packages

# 替换 VERSION_STRING 为指定版本号即可,例如:5:20.10.8~3-0~ubuntu-hirsute
sudo apt-get install docker-ce=<VERSION_STRING> docker-ce-cli=<VERSION_STRING> containerd.io

验证是否安装成功

sudo docker run hello-world

当出现以下提示,证明安装成功


image.png
三、mac (等有 mac 时再补......)

相关文章

网友评论

    本文标题:Docker 入门教程之安装

    本文链接:https://www.haomeiwen.com/subject/eoodpltx.html