Home 树莓派安装docker
Post
Cancel

树莓派安装docker

树莓派系统

树莓派版本 - 树莓派 4b 8g 系统版本 - Raspberry Pi OS Lite(64-bit) 2022-04-04 Raspberry Os

Install Docker Engine

Install Docker Engine中选择支持的平台,这里选择Raspbian,可以看到其实也是 Debian 的路径。

以下步骤与官网相同

卸载旧版本

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

开始安装

设置源

1
2
3
4
5
sudo apt-get install \
    ca-certificates \
    curl \
    gnupg \
    lsb-release
1
curl -fsSL https://download.docker.com/linux/debian/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
1
2
3
echo \
  "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/debian \
  $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
1
sudo apt-get update

下载Engine

查看apt中有哪些版本

1
apt-cache madison docker-ce

输出

1
2
3
4
5
6
7
8
9
10
➜  ~ apt-cache madison docker-ce
docker-ce | 5:20.10.14~3-0~debian-bullseye | https://download.docker.com/linux/debian bullseye/stable arm64 Packages
docker-ce | 5:20.10.13~3-0~debian-bullseye | https://download.docker.com/linux/debian bullseye/stable arm64 Packages
docker-ce | 5:20.10.12~3-0~debian-bullseye | https://download.docker.com/linux/debian bullseye/stable arm64 Packages
docker-ce | 5:20.10.11~3-0~debian-bullseye | https://download.docker.com/linux/debian bullseye/stable arm64 Packages
docker-ce | 5:20.10.10~3-0~debian-bullseye | https://download.docker.com/linux/debian bullseye/stable arm64 Packages
docker-ce | 5:20.10.9~3-0~debian-bullseye | https://download.docker.com/linux/debian bullseye/stable arm64 Packages
docker-ce | 5:20.10.8~3-0~debian-bullseye | https://download.docker.com/linux/debian bullseye/stable arm64 Packages
docker-ce | 5:20.10.7~3-0~debian-bullseye | https://download.docker.com/linux/debian bullseye/stable arm64 Packages
docker-ce | 5:20.10.6~3-0~debian-bullseye | https://download.docker.com/linux/debian bullseye/stable arm64 Packages

下载指定版本的engine

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

例如下载5:20.10.14~3-0~debian-bullseye

1
sudo apt-get install docker-ce=5:20.10.14~3-0~debian-bullseye docker-ce-cli=5:20.10.14~3-0~debian-bullseye containerd.io

直接下载最新版

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

这里下载docker-ce时可能提示有错(如果没错就表示安装完成了,可以直接下一步了)

1
2
3
4
5
6
7
8
9
10
11
12
13
➜  ~ sudo apt-get install docker-ce docker-ce-cli containerd.io
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
Some packages could not be installed. This may mean that you have
requested an impossible situation or if you are using the unstable
distribution that some required packages have not yet been created
or been moved out of Incoming.
The following information may help to resolve the situation:

The following packages have unmet dependencies:
 docker-ce : Depends: iptables
E: Unable to correct problems, you have held broken packages.

可以看出docker-ce : Depends: iptables提示iptables需要先下载,那么就先下载iptables

1
sudo apt-get install iptables

输出

1
2
3
4
5
6
7
8
9
10
11
12
13
➜  ~ sudo apt-get install iptables
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
Some packages could not be installed. This may mean that you have
requested an impossible situation or if you are using the unstable
distribution that some required packages have not yet been created
or been moved out of Incoming.
The following information may help to resolve the situation:

The following packages have unmet dependencies:
 iptables : Depends: libxtables12 (= 1.8.2-4) but 1.8.7-1 is to be installed
E: Unable to correct problems, you have held broken packages.

可以看出这里依赖的libxtables12版本不是最新的,使用apt-cache madison libxtables12查看可用版本

1
2
3
➜  ~ apt-cache madison libxtables12
libxtables12 | 1.8.5-3~bpo10+1 | https://mirrors.tuna.tsinghua.edu.cn/debian buster-backports/main arm64 Packages
libxtables12 |    1.8.2-4 | https://mirrors.tuna.tsinghua.edu.cn/debian buster/main arm64 Packages

直接下载对应版本

1
sudo apt-get install libxtables12=1.8.2-4

再下载

1
sudo apt-get install iptables

最后下载engine

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

上面的选择了更旧的版本,但是这里测试过也可以都更新成最新的版本,只要版本号一直都按范围匹配就行了,这里就不再啰嗦的都列上了

测试安装效果

1
sudo docker run hello-world

输出,可以看到已经可以正常运行了

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
➜  ~ sudo docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
7050e35b49f5: Pull complete
Digest: sha256:10d7d58d5ebd2a652f4d93fdd86da8f265f5318c6a73cc5b6a9798ff6d2b2e67
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.
    (arm64v8)
 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/

修改镜像源

创建文件

1
sudo vim /etc/docker/daemon.json

添加

1
2
3
4
5
6
{
    "registry-mirrors": [
        "https://docker.mirrors.ustc.edu.cn", # 中国技术大学
        "https://registry.docker-cn.com" # docker中国
    ]
}

重启

1
sudo service docker restart
This post is licensed under CC BY 4.0 by the author.