树莓派安装Docker CE

树莓派卡片电脑安装 Docker CE

警告:切勿在没有配置 Docker APT 源的状况下直接使用 apt 命令安装 Docker.linux

系统要求

Docker CE 不只支持 x86_64 架构的计算机,同时也支持 ARM 架构的计算机,本小节内容以树莓派单片电脑为例讲解 ARM 架构安装 Docker CE。docker

Docker CE 支持如下版本的 Raspbian 操做系统:ubuntu

  • Raspbian Stretch缓存

  • Raspbian Jessie安全

注: Raspbian 是树莓派的开发与维护机构 树莓派基金会 推荐用于树莓派的首选系统,其基于 Debianbash

使用 APT 安装

因为 apt 源使用 HTTPS 以确保软件下载过程当中不被篡改。所以,咱们首先须要添加使用 HTTPS 传输的软件包以及 CA 证书。网络

$ sudo apt-get update

$ sudo apt-get install \
     apt-transport-https \
     ca-certificates \
     curl \
     gnupg2 \
     lsb-release \
     software-properties-common

鉴于国内网络问题,强烈建议使用国内源,官方源请在注释中查看。架构

为了确认所下载软件包的合法性,须要添加软件源的 GPG 密钥。app

$ curl -fsSL https://mirrors.ustc.edu.cn/docker-ce/linux/raspbian/gpg | sudo apt-key add -


# 官方源 # $ curl -fsSL https://download.docker.com/linux/raspbian/gpg | sudo apt-key add - 

而后,咱们须要向 source.list 中添加 Docker CE 软件源:dom

$ sudo add-apt-repository \
    "deb [arch=armhf] https://mirrors.ustc.edu.cn/docker-ce/linux/raspbian \ $(lsb_release -cs) \ stable" # 官方源 # $ sudo add-apt-repository \ # "deb [arch=armhf] https://download.docker.com/linux/raspbian \ # $(lsb_release -cs) \ # stable" 

以上命令会添加稳定版本的 Docker CE APT 源,若是须要测试或每日构建版本的 Docker CE 请将 stable 改成 test 或者 nightly。

安装 Docker CE

更新 apt 软件包缓存,并安装 docker-ce

$ sudo apt-get update

$ sudo apt-get install docker-ce

使用脚本自动安装

在测试或开发环境中 Docker 官方为了简化安装流程,提供了一套便捷的安装脚本,Raspbian 系统上可使用这套脚本安装:

$ curl -fsSL get.docker.com -o get-docker.sh
$ sudo sh get-docker.sh --mirror Aliyun

执行这个命令后,脚本就会自动的将一切准备工做作好,而且把 Docker CE 的 Edge 版本安装在系统中。

启动 Docker CE

$ sudo systemctl enable docker $ sudo systemctl start docker 

创建 docker 用户组

默认状况下,docker 命令会使用 Unix socket 与 Docker 引擎通信。而只有 root 用户和 docker 组的用户才能够访问 Docker 引擎的 Unix socket。出于安全考虑,通常 Linux 系统上不会直接使用 root 用户。所以,更好地作法是将须要使用 docker 的用户加入 docker 用户组。

创建 docker 组:

$ sudo groupadd docker

将当前用户加入 docker 组:

$ sudo usermod -aG docker $USER 

退出当前终端并从新登陆,进行以下测试。

测试 Docker 是否安装正确

$ docker run arm32v7/hello-world

Unable to find image 'hello-world:latest' locally latest: Pulling from library/hello-world ca4f61b1923c: Pull complete Digest: sha256:be0cd392e45be79ffeffa6b05338b98ebb16c87b255f48e297ec7f98e123905c 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://cloud.docker.com/ For more examples and ideas, visit: https://docs.docker.com/engine/userguide/ 

若能正常输出以上信息,则说明安装成功。

注意: ARM 平台不能使用 x86 镜像,查看 Raspbian 可以使用镜像请访问 arm32v7

镜像加速

鉴于国内网络问题,后续拉取 Docker 镜像十分缓慢,强烈建议安装 Docker 以后配置镜像加速

相关文章
相关标签/搜索