Docker -- 安装(三)

一、Ubuntu Docker 安装

Docker 支持以下的 Ubuntu 版本:

  • Xenial 16.04 (LTS)
  • Bionic 18.04 (LTS)
  • Cosmic 18.10
  • Disco 19.04
  • 其他更新的版本……

Docker Engine - Community 支持上 x86_64(或 amd64)armhf,arm64,s390x (IBM Z),和 ppc64le(IBM的Power)架构。

1、前提条件

Docker 要求 Ubuntu 系统的内核版本高于 3.10 ,查看本页面的前提条件来验证你的 Ubuntu 版本是否支持 Docker。

通过 uname -r 命令查看你当前的内核版本。

2、使用官方安装脚本自动安装

(1)安装命令如下:

curl -fsSL https://get.docker.com | bash -s docker --mirror Aliyun

也可以使用国内 daocloud 一键安装命令:

curl -sSL https://get.daocloud.io/docker | sh

 

3、手动安装

(1) 卸载旧版本

Docker 的旧版本被称为 docker,docker.io 或 docker-engine 。如果已安装,请卸载它们:

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

当前称为 Docker Engine-Community 软件包 docker-ce 。

安装 Docker Engine-Community,以下介绍两种方式。

(2) 使用 Docker 仓库进行安装

在新主机上首次安装 Docker Engine-Community 之前,需要设置 Docker 仓库。之后,您可以从仓库安装和更新 Docker 。

(3) 设置仓库

更新 apt 包索引。

$ sudo apt-get update

 安装 apt 依赖包,用于通过HTTPS来获取仓库:

$ sudo apt-get install \
    apt-transport-https \
    ca-certificates \
    curl \
    gnupg-agent \
    software-properties-common

 添加 Docker 的官方 GPG 密钥:

$ curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -

9DC8 5822 9FC7 DD38 854A E2D8 8D81 803C 0EBF CD88 通过搜索指纹的后8个字符,验证您现在是否拥有带有指纹的密钥。

$ sudo apt-key fingerprint 0EBFCD88
   
pub   rsa4096 2017-02-22 [SCEA]
      9DC8 5822 9FC7 DD38 854A  E2D8 8D81 803C 0EBF CD88
uid           [ unknown] Docker Release (CE deb) <docker@docker.com>
sub   rsa4096 2017-02-22 [S]

 使用以下指令设置稳定版仓库

$ sudo add-apt-repository \
   "deb [arch=amd64] https://download.docker.com/linux/ubuntu \
  $(lsb_release -cs) \
  stable"

 (4) 安装 Docker Engine-Community

更新 apt 包索引。

$ sudo apt-get update

安装最新版本的 Docker Engine-Community 和 containerd ,或者转到下一步安装特定版本:

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

要安装特定版本的 Docker Engine-Community,请在仓库中列出可用版本,然后选择一种安装。列出您的仓库中可用的版本:

$ apt-cache madison docker-ce

  docker-ce | 5:18.09.1~3-0~ubuntu-xenial | https://download.docker.com/linux/ubuntu  xenial/stable amd64 Packages
  docker-ce | 5:18.09.0~3-0~ubuntu-xenial | https://download.docker.com/linux/ubuntu  xenial/stable amd64 Packages
  docker-ce | 18.06.1~ce~3-0~ubuntu       | https://download.docker.com/linux/ubuntu  xenial/stable amd64 Packages
  docker-ce | 18.06.0~ce~3-0~ubuntu       | https://download.docker.com/linux/ubuntu  xenial/stable amd64 Packages
  ...

使用第二列中的版本字符串安装特定版本,例如 5:18.09.1~3-0~ubuntu-xenial。

$ sudo apt-get install docker-ce=<VERSION_STRING> docker-ce-cli=<VERSION_STRING> containerd.io

测试 Docker 是否安装成功,输入以下指令,打印出以下信息则安装成功:

$ sudo docker run hello-world

Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
1b930d010525: Pull complete                                                                                                                                  Digest: sha256:c3b4ada4687bbaa170745b3e4dd8ac3f194ca95b2d0518b417fb47e5879d9b5f
Status: Downloaded newer image for hello-world:latest


Hello from Docker!
This message shows that your installation appears to be working correctly.


To generate this message, Docker took the following steps:
 1. The Docker client contacted the Docker daemon.
 2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
    (amd64)
 3. The Docker daemon created a new container from that image which runs the
    executable that produces the output you are currently reading.
 4. The Docker daemon streamed that output to the Docker client, which sent it
    to your terminal.


To try something more ambitious, you can run an Ubuntu container with:
 $ docker run -it ubuntu bash


Share images, automate workflows, and more with a free Docker ID:
 https://hub.docker.com/


For more examples and ideas, visit:
 https://docs.docker.com/get-started/

 4、使用 Shell 脚本进行安装

Docker 在 get.docker.com 和 test.docker.com 上提供了方便脚本,用于将快速安装 Docker Engine-Community 的边缘版本和测试版本。脚本的源代码在 docker-install 仓库中。 不建议在生产环境中使用这些脚本,在使用它们之前,您应该了解潜在的风险:

  • 脚本需要运行 root 或具有 sudo 特权。因此,在运行脚本之前,应仔细检查和审核脚本。

  • 这些脚本尝试检测 Linux 发行版和版本,并为您配置软件包管理系统。此外,脚本不允许您自定义任何安装参数。从 Docker 的角度或您自己组织的准则和标准的角度来看,这可能导致不支持的配置。

  • 这些脚本将安装软件包管理器的所有依赖项和建议,而无需进行确认。这可能会安装大量软件包,具体取决于主机的当前配置。

  • 该脚本未提供用于指定要安装哪个版本的 Docker 的选项,而是安装了在 edge 通道中发布的最新版本。

  • 如果已使用其他机制将 Docker 安装在主机上,请不要使用便捷脚本。

本示例使用 get.docker.com 上的脚本在 Linux 上安装最新版本的Docker Engine-Community。要安装最新的测试版本,请改用 test.docker.com。在下面的每个命令,取代每次出现 get 用 test。

$ curl -fsSL https://get.docker.com -o get-docker.sh
$ sudo sh get-docker.sh

 如果要使用 Docker 作为非 root 用户,则应考虑使用类似以下方式将用户添加到 docker 组:

$ sudo usermod -aG docker your-user

二、CentOS Docker 安装

Docker 支持以下的 64 位 CentOS 版本:

  • CentOS 7
  • CentOS 8
  • 更高版本...

1、使用官方安装脚本自动安装

安装命令如下:

curl -fsSL https://get.docker.com | bash -s docker --mirror Aliyun

也可以使用国内 daocloud 一键安装命令:

curl -sSL https://get.daocloud.io/docker | sh

2、手动安装

(1)卸载旧版本

较旧的 Docker 版本称为 docker 或 docker-engine 。如果已安装这些程序,请卸载它们以及相关的依赖项。

$ sudo yum remove docker \
                  docker-client \
                  docker-client-latest \
                  docker-common \
                  docker-latest \
                  docker-latest-logrotate \
                  docker-logrotate \
                  docker-engine

(2)安装 Docker Engine-Community

(3)使用 Docker 仓库进行安装

在新主机上首次安装 Docker Engine-Community 之前,需要设置 Docker 仓库。之后,您可以从仓库安装和更新 Docker。

设置仓库

安装所需的软件包。yum-utils 提供了 yum-config-manager ,并且 device mapper 存储驱动程序需要 device-mapper-persistent-data 和 lvm2。

$ sudo yum install -y yum-utils \
  device-mapper-persistent-data \
  lvm2

 使用以下命令来设置稳定的仓库。

 

使用官方源地址(比较慢)
$ sudo yum-config-manager \
    --add-repo \
    https://download.docker.com/linux/centos/docker-ce.repo

可以选择国内的一些源地址:

阿里云
$ sudo yum-config-manager \
    --add-repo \
    http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo

 

清华大学源
$ sudo yum-config-manager \
    --add-repo \
    https://mirrors.tuna.tsinghua.edu.cn/docker-ce/linux/centos/docker-ce.repo

(4)安装 Docker Engine-Community

安装最新版本的 Docker Engine-Community 和 containerd,或者转到下一步安装特定版本:

$ sudo yum install docker-ce docker-ce-cli containerd.io

如果提示您接受 GPG 密钥,请选是。

有多个 Docker 仓库吗?

如果启用了多个 Docker 仓库,则在未在 yum install 或 yum update 命令中指定版本的情况下,进行的安装或更新将始终安装最高版本,这可能不适合您的稳定性需求。

 Docker 安装完默认未启动。并且已经创建好 docker 用户组,但该用户组下没有用户。

要安装特定版本的 Docker Engine-Community,请在存储库中列出可用版本,然后选择并安装:

1、列出并排序您存储库中可用的版本。此示例按版本号(从高到低)对结果进行排序。

 

$ yum list docker-ce --showduplicates | sort -r

docker-ce.x86_64  3:18.09.1-3.el7                     docker-ce-stable
docker-ce.x86_64  3:18.09.0-3.el7                     docker-ce-stable
docker-ce.x86_64  18.06.1.ce-3.el7                    docker-ce-stable
docker-ce.x86_64  18.06.0.ce-3.el7                    docker-ce-stable

2、通过其完整的软件包名称安装特定版本,该软件包名称是软件包名称(docker-ce)加上版本字符串(第二列),从第一个冒号(:)一直到第一个连字符,并用连字符(-)分隔。例如:docker-ce-18.09.1。

 

$ sudo yum install docker-ce-<VERSION_STRING> docker-ce-cli-<VERSION_STRING> containerd.io

启动 Docker。

$ sudo systemctl start docker

通过运行 hello-world 映像来验证是否正确安装了 Docker Engine-Community 。

$ sudo docker run hello-world

三、Windows Docker 安装

1、win7、win8 系统

win7、win8 等需要利用 docker toolbox 来安装,国内可以使用阿里云的镜像来下载,下载地址:http://mirrors.aliyun.com/docker-toolbox/windows/docker-toolbox/

安装比较简单,双击运行,点下一步即可,可以勾选自己需要的组件:

 

 

 

 

 

 

docker toolbox 是一个工具集,它主要包含以下一些内容:

  • Docker CLI - 客户端,用来运行 docker 引擎创建镜像和容器。
  • Docker Machine - 可以让你在 Windows 的命令行中运行 docker 引擎命令。
  • Docker Compose - 用来运行 docker-compose 命令。
  • Kitematic - 这是 Docker 的 GUI 版本。
  • Docker QuickStart shell - 这是一个已经配置好Docker的命令行环境。
  • Oracle VM Virtualbox - 虚拟机。

下载完成之后直接点击安装,安装成功后,桌边会出现三个图标,入下图所示:

点击 Docker QuickStart 图标来启动 Docker Toolbox 终端。

如果系统显示 User Account Control 窗口来运行 VirtualBox 修改你的电脑,选择 Yes。

 $ 符号那你可以输入以下命令来执行。

$ docker run hello-world
 Unable to find image 'hello-world:latest' locally
 Pulling repository hello-world
 91c95931e552: Download complete
 a8219747be10: Download complete
 Status: Downloaded newer image for hello-world:latest
 Hello from Docker.
 This message shows that your installation appears to be working correctly.

 To generate this message, Docker took the following steps:
  1. The Docker Engine CLI client contacted the Docker Engine daemon.
  2. The Docker Engine daemon pulled the "hello-world" image from the Docker Hub.
     (Assuming it was not already locally available.)
  3. The Docker Engine daemon created a new container from that image which runs the
     executable that produces the output you are currently reading.
  4. The Docker Engine daemon streamed that output to the Docker Engine CLI client, which sent it
     to your terminal.

 To try something more ambitious, you can run an Ubuntu container with:
  $ docker run -it ubuntu bash

 For more examples and ideas, visit:
  https://docs.docker.com/userguide/

2、Win10 系统

现在 Docker 有专门的 Win10 专业版系统的安装包,需要开启Hyper-V。

(1)开启 Hyper-V

程序和功能

启用或关闭Windows功能

 选中Hyper-V

(2)安装 Toolbox

最新版 Toolbox 下载地址: 访问 https://www.docker.com/get-started,注册一个账号,然后登录。

点击 Get started with Docker Desktop,并下载 Windows 的版本,如果你还没有登录,会要求注册登录:

 

 

(3)运行安装文件

双击下载的 Docker for Windows Installe 安装文件,一路 Next,点击 Finish 完成安装。

安装完成后,Docker 会自动启动。通知栏上会出现个小鲸鱼的图标,这表示 Docker 正在运行。

桌边也会出现三个图标,入下图所示:

我们可以在命令行执行 docker version 来查看版本号,docker run hello-world 来载入测试镜像测试。

如果没启动,你可以在 Windows 搜索 Docker 来启动:

启动后,也可以在通知栏上看到小鲸鱼图标:

3、镜像加速

Windows 10

对于使用 Windows 10 的系统,在系统右下角托盘 Docker 图标内右键菜单选择 Settings,打开配置窗口后左侧导航菜单选择 Daemon。在 Registrymirrors 一栏中填写加速器地址 https://registry.docker-cn.com ,之后点击 Apply 保存后 Docker 就会重启并应用配置的镜像地址了。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值