安装方法一(脚本安装)

脚本安装是最推荐的方式,只需要输入下面的命令,等待自动安装好即可。

sudo curl -sSL https://get.docker.com | sh

如果采用这一步安装成功,可直接跳到下文的图形界面安装那里继续阅读。

pi@raspberrypi:~ $ sudo curl -sSL https://get.docker.com | sh
# Executing docker install script, commit: 26ff363bcf3b3f5a00498ac43694bf1c7d9ce16c
+ sudo -E sh -c apt-get update -qq >/dev/null
+ sudo -E sh -c DEBIAN_FRONTEND=noninteractive apt-get install -y -qq apt-transport-https ca-certificates curl >/dev/null
+ sudo -E sh -c curl -fsSL "https://download.docker.com/linux/raspbian/gpg" | apt-key add -qq - >/dev/null
Warning: apt-key output should not be parsed (stdout is not a terminal)
+ sudo -E sh -c echo "deb [arch=armhf] https://download.docker.com/linux/raspbian stretch stable" > /etc/apt/sources.list.d/docker.list
+ sudo -E sh -c apt-get update -qq >/dev/null
+ [ -n  ]
+ sudo -E sh -c apt-get install -y -qq --no-install-recommends docker-ce >/dev/null
+ sudo -E sh -c docker version
    Client: Docker Engine - Community
     Version:           19.03.9
     API version:       1.40
     Go version:        go1.13.10
     Git commit:        9d98839
     Built:             Fri May 15 00:34:22 2020
     OS/Arch:           linux/arm
     Experimental:      false
    
    Server: Docker Engine - Community
     Engine:
      Version:          19.03.9
      API version:      1.40 (minimum version 1.12)
      Go version:       go1.13.10
      Git commit:       9d98839
      Built:            Fri May 15 00:28:27 2020
      OS/Arch:          linux/arm
      Experimental:     false
     containerd:
      Version:          1.2.13
      GitCommit:        7ad184331fa3e55e52b890ea95e65ba581ae3429
     runc:
      Version:          1.0.0-rc10
      GitCommit:        dc9208a3303feef5b3839f4323d9beb36df0a9dd
     docker-init:
      Version:          0.18.0
      GitCommit:        fec3683
    If you would like to use Docker as a non-root user, you should now consider
    adding your user to the "docker" group with something like:
    
      sudo usermod -aG docker pi
    
    Remember that you will have to log out and back in for this to take effect!
    
    WARNING: Adding a user to the "docker" group will grant the ability to run
             containers which can be used to obtain root privileges on the
             docker host.
             Refer to https://docs.docker.com/engine/security/security/#docker-daemon-attack-surface
             for more information.

安装方法二(apt 安装)

由于 Raspbian 基于 Debian,我们还可以使用 apt 来安装 Docker,首先需要更新一下软件包的索引。

sudo apt-get update

安装 HTTPS 所依赖的包

sudo apt-get install apt-transport-https \
                         ca-certificates \
                         software-properties-common

添加 Docker 的 GPG key

curl -fsSL https://yum.dockerproject.org/gpg | sudo apt-key add -

验证 key id:

apt-key fingerprint 58118E89F3A912897C070ADBF76221572C52609D

设置稳定的 repository:

sudo add-apt-repository \
     "deb https://apt.dockerproject.org/repo/ \
      raspbian-$(lsb_release -cs) \
      main"

注意:如果 add-apt-repository 命令遇到问题,可以尝试将下面这行添加到树莓派软件源 sources.list,操作如下:

sudo nano /etc/apt/sources.list

添加一行:

deb https://apt.dockerproject.org/repo/ raspbian-RELEASE main

根据自己系统版本调整上面的 RELEASE。通过下面的命令可以查看发行版。

lsb_release -cs

安装 Docker

sudo apt-get update
sudo apt-get -y install docker-engine

常用配置和工具命令

#查看 Docker 版本 docker -v sudo docker pull 仓库/镜像:版本(留空的话默认为 latest) sudo docker run 加参数,用来创建容器
#查看运行容器 sudo docker ps
#查看所有下载的镜像 sudo docker images
#进入容器终端 sudo docker exec -i -t ha /bin/bash
#实时查看10行的 ha 日志 sudo docker logs -f -t --tail 10 ha
#重启 systemctl 守护进程 sudo systemctl daemon-reload
#设置 Docker 开机启动 sudo systemctl enable docker
#开启 Docker 服务 sudo systemctl start docker  
#下载 Docker 图形化界面 portainer sudo docker pull portainer/portainer
#创建 portainer 容器 sudo docker volume create portainer_data
#运行 portainer sudo docker run -d -p 9000:9000 --name portainer --restart always -v /var/run/docker.sock:/var/run/docker.sock -v portainer_data:/data portainer/portainer

安装UI

    pi@raspberrypi:~ $ sudo docker pull portainer/portainer
    Using default tag: latest
    latest: Pulling from portainer/portainer
    d1e017099d17: Pull complete 
    860ebb866910: Pull complete 
    Digest: sha256:4ae7f14330b56ffc8728e63d355bc4bc7381417fa45ba0597e5dd32682901080
    Status: Downloaded newer image for portainer/portainer:latest
    docker.io/portainer/portainer:latest

    pi@raspberrypi:~ $ sudo docker volume create portainer_data
    portainer_data
    pi@raspberrypi:~ $ sudo docker run -d -p 99:9000 --name portainer --restart always -v /var/run/docker.sock:/var/run/docker.sock -v portainer_data:/data portainer/portainer 
    b35b6a798ac0866e65374a4e1a861fd6b73c6478788dfa63bf1323f278eac651
    pi@raspberrypi:~ $ 
http://192.168.50.8:99/
最后修改:2020 年 12 月 15 日 12 : 53 PM
如果觉得我的文章对你有用,请随意赞赏