Difference between revisions of "How to Install Docker on Debian/zh"

From FriendlyELEC WiKi
Jump to: navigation, search
(updated by API)
(updated by API)
 
(2 intermediate revisions by the same user not shown)
Line 1: Line 1:
 
[[How to Install Docker on Debian|English]]
 
[[How to Install Docker on Debian|English]]
 
==本文适应范围==
 
==本文适应范围==
* 平台: RK3328/RK3399/RK3568/RK3588<br>
+
* 支持的平台: RK3328/RK3399/RK3568/RK3588<br>
* 操作系统: Debian10, Debian11<br>
+
* 支持的目标板操作系统: debian-bookworm-core, debian-bullseye-minimal, debian-buster-desktop, debian-buster-desktop<br>
 
==安装前的检查和准备==
 
==安装前的检查和准备==
 
Docker现在推荐使用的存储驱动是Overlay2, 而由于根文件系统已经使用了OverlayFS, 所以可能无法直接安装,需要对分区作些调整,有如下几种方法, 下面将分别介绍, 请根据需要选择其中一种:<br />
 
Docker现在推荐使用的存储驱动是Overlay2, 而由于根文件系统已经使用了OverlayFS, 所以可能无法直接安装,需要对分区作些调整,有如下几种方法, 下面将分别介绍, 请根据需要选择其中一种:<br />
Line 35: Line 35:
 
sudo apt update
 
sudo apt update
 
sudo apt install parted fdisk
 
sudo apt install parted fdisk
export DEV=/dev/mmcblkX
+
export DEV=/dev/mmcblkX # 需要改成真实的设备
 
sudo parted -s ${DEV} unit MiB print
 
sudo parted -s ${DEV} unit MiB print
 
</syntaxhighlight>
 
</syntaxhighlight>
Line 60: Line 60:
 
sudo mkdir /var/lib/docker
 
sudo mkdir /var/lib/docker
 
sudo blkid ${DEV}p${NUM}
 
sudo blkid ${DEV}p${NUM}
 +
# 记下UUID
 
# 配置开机自动挂载新创建的分区
 
# 配置开机自动挂载新创建的分区
 
sudo vi /etc/fstab
 
sudo vi /etc/fstab
 
# 在文件末尾加入如下内容(其中UUID需替换为真实的)
 
# 在文件末尾加入如下内容(其中UUID需替换为真实的)
UUID=f4b0684c-4afa-4f8d-97c8-6768fd6bb4d8 /var/lib/docker ext4 suid,dev,exec,auto,nouser,async,noatime,nofail 0 0
+
UUID=bbb06fe1-df52-4c7c-b2eb-926b14605fe4 /var/lib/docker ext4 suid,dev,exec,auto,nouser,async,noatime,nofail 0 0
 
# 输入以下命令挂载分区
 
# 输入以下命令挂载分区
 
sudo mount /var/lib/docker
 
sudo mount /var/lib/docker
Line 77: Line 78:
 
sudo apt install lsb-release wget
 
sudo apt install lsb-release wget
 
codename=$(lsb_release -c | awk '{print $2}')
 
codename=$(lsb_release -c | awk '{print $2}')
wget https://download.docker.com/linux/debian/dists/${codename}/pool/stable/arm64/containerd.io_1.6.9-1_arm64.deb
+
version=$(lsb_release -sr | cut -d'.' -f1)
wget https://download.docker.com/linux/debian/dists/${codename}/pool/stable/arm64/docker-ce-cli_23.0.1-1~debian.11~${codename}_arm64.deb
+
wget https://download.docker.com/linux/debian/dists/${codename}/pool/stable/arm64/containerd.io_1.6.24-1_arm64.deb
wget https://download.docker.com/linux/debian/dists/${codename}/pool/stable/arm64/docker-buildx-plugin_0.10.2-1~debian.11~${codename}_arm64.deb
+
wget https://download.docker.com/linux/debian/dists/${codename}/pool/stable/arm64/docker-ce-cli_24.0.6-1~debian.${version}~${codename}_arm64.deb
wget https://download.docker.com/linux/debian/dists/${codename}/pool/stable/arm64/docker-ce_23.0.1-1~debian.11~${codename}_arm64.deb
+
wget https://download.docker.com/linux/debian/dists/${codename}/pool/stable/arm64/docker-buildx-plugin_0.11.2-1~debian.${version}~${codename}_arm64.deb
wget https://download.docker.com/linux/debian/dists/${codename}/pool/stable/arm64/docker-compose-plugin_2.6.0~debian-${codename}_arm64.deb
+
wget https://download.docker.com/linux/debian/dists/${codename}/pool/stable/arm64/docker-ce_24.0.6-1~debian.${version}~${codename}_arm64.deb
sudo dpkg -i ./containerd.io_1.6.9-1_arm64.deb \
+
wget https://download.docker.com/linux/debian/dists/${codename}/pool/stable/arm64/docker-compose-plugin_2.21.0-1~debian.11~${codename}_arm64.deb
   ./docker-ce_23.0.1-1~debian.11~${codename}_arm64.deb \
+
sudo apt install ./containerd.io_1.6.24-1_arm64.deb \
   ./docker-ce-cli_23.0.1-1~debian.11~${codename}_arm64.deb \
+
   ./docker-ce_24.0.6-1~debian.${version}~${codename}_arm64.deb \
   ./docker-buildx-plugin_0.10.2-1~debian.11~${codename}_arm64.deb \
+
   ./docker-ce-cli_24.0.6-1~debian.${version}~${codename}_arm64.deb \
   ./docker-compose-plugin_2.6.0~debian-${codename}_arm64.deb
+
   ./docker-buildx-plugin_0.11.2-1~debian.${version}~${codename}_arm64.deb \
 +
   ./docker-compose-plugin_2.21.0-1~debian.11~${codename}_arm64.deb
 
</syntaxhighlight>
 
</syntaxhighlight>
 
* 验证是否安装成功:
 
* 验证是否安装成功:

Latest revision as of 08:18, 1 July 2024

English

1 本文适应范围

  • 支持的平台: RK3328/RK3399/RK3568/RK3588
  • 支持的目标板操作系统: debian-bookworm-core, debian-bullseye-minimal, debian-buster-desktop, debian-buster-desktop

2 安装前的检查和准备

Docker现在推荐使用的存储驱动是Overlay2, 而由于根文件系统已经使用了OverlayFS, 所以可能无法直接安装,需要对分区作些调整,有如下几种方法, 下面将分别介绍, 请根据需要选择其中一种:

方法1
让根文件系统不再使用OverlayFS, 最省事,但由于"恢复出厂设置"这个功能需要依赖OverlayFS,所以此功能将无法工作;
方法2
创建一个额外的分区用来挂载/var/lib/docker目录, 需要预先规划好分区大小;
方法3
将/var/lib/docker目录挂载到例如U盘和M.2 SSD这样的外置存储设备上,存储设备需要格式化为ext4格式, 本文主要讨论上面两种;


注意事项:

  • 此操作会擦除用户数据,需要预先备份好数据
  • 需要将固件更新至2023/03/14或之后的版本,或者单独更新boot.img
  • 命令中出现的/dev/mmcblkX设备节点是虚构的节点,需要改成真实的设备,eMMC的设备节点是/dev/mmcblk2,TF卡的设备节点是/dev/mmcblk0

3 方法1: 让根文件系统不使用OverlayFS

  • 写特定内容到 /.init_wipedata 后重启
sudo passwd root  # 为root用户创建密码,如果之前没有做
su - root -c 'echo "overlayfs=disable" > /.init_wipedata'
sudo reboot
  • 重启后,使用parted命令查看当前的分区布局,正常情况下,可以看到根系统是以ext4格式挂载的,而不是之前的overlay:
sudo apt update
sudo apt install parted
export DEV=/dev/mmcblkX # 需要改成真实的设备
sudo parted -s ${DEV} unit MiB print

4 方法2: 创建一个额外的分区用于docker

  • 查看当前的分区布局
sudo apt update
sudo apt install parted fdisk
export DEV=/dev/mmcblkX # 需要改成真实的设备
sudo parted -s ${DEV} unit MiB print
  • 调整userdata分区的大小

这里以调整为8G大小为例:

sudo passwd root  # 为root用户创建密码,如果之前没有做
su - root -c 'echo "overlayfs=enable userdata=8096" > /.init_wipedata'
sudo reboot

重启后, 正常情况下,可以看到userdata分区已调整为8GB:

export DEV=/dev/mmcblkX  # 需要改成真实的设备
sudo parted -s ${DEV} unit MiB print
  • 创建新分区并格式化
(echo n; echo ""; echo ""; echo ""; echo w) | sudo fdisk ${DEV}
NUM=$(sudo parted ${DEV} print | awk 'NF > 1 {p = $1} END {print p}')  # 获取最后一个分区的序号
sudo mkfs.ext4 ${DEV}p${NUM}
  • 挂载新分区到docker数据目录
sudo mkdir /var/lib/docker
sudo blkid ${DEV}p${NUM}
# 记下UUID
# 配置开机自动挂载新创建的分区
sudo vi /etc/fstab
# 在文件末尾加入如下内容(其中UUID需替换为真实的)
UUID=bbb06fe1-df52-4c7c-b2eb-926b14605fe4 /var/lib/docker ext4 suid,dev,exec,auto,nouser,async,noatime,nofail 0 0
# 输入以下命令挂载分区
sudo mount /var/lib/docker

5 安装docker

  • 因Docker安装程序需要使用iptables, 而Debian默认使用的是nftables, 因此安装前先设置Debian使用传统的iptables:
[ -f /usr/sbin/iptables-legacy ] && sudo update-alternatives --set iptables /usr/sbin/iptables-legacy
[ -f /usr/sbin/ip6tables-legacy ] && sudo update-alternatives --set ip6tables /usr/sbin/ip6tables-legacy
  • 开始安装Docker:
sudo apt install lsb-release wget
codename=$(lsb_release -c | awk '{print $2}')
version=$(lsb_release -sr | cut -d'.' -f1)
wget https://download.docker.com/linux/debian/dists/${codename}/pool/stable/arm64/containerd.io_1.6.24-1_arm64.deb
wget https://download.docker.com/linux/debian/dists/${codename}/pool/stable/arm64/docker-ce-cli_24.0.6-1~debian.${version}~${codename}_arm64.deb
wget https://download.docker.com/linux/debian/dists/${codename}/pool/stable/arm64/docker-buildx-plugin_0.11.2-1~debian.${version}~${codename}_arm64.deb
wget https://download.docker.com/linux/debian/dists/${codename}/pool/stable/arm64/docker-ce_24.0.6-1~debian.${version}~${codename}_arm64.deb
wget https://download.docker.com/linux/debian/dists/${codename}/pool/stable/arm64/docker-compose-plugin_2.21.0-1~debian.11~${codename}_arm64.deb
sudo apt install ./containerd.io_1.6.24-1_arm64.deb \
  ./docker-ce_24.0.6-1~debian.${version}~${codename}_arm64.deb \
  ./docker-ce-cli_24.0.6-1~debian.${version}~${codename}_arm64.deb \
  ./docker-buildx-plugin_0.11.2-1~debian.${version}~${codename}_arm64.deb \
  ./docker-compose-plugin_2.21.0-1~debian.11~${codename}_arm64.deb
  • 验证是否安装成功:
sudo docker info
  • 看看Docker是否使用了overlay2存储驱动:
$ sudo docker info | grep storage -i
 Storage Driver: overlay2

6 配置非root用户使用docker

sudo groupadd docker
sudo gpasswd -a ${USER} docker
sudo systemctl restart docker
sudo chmod a+rw /var/run/docker.sock

验证是否成功:

docker images

7 测试运行docker映像: 安装nextcloud网盘

mkdir ~/nextcloud -p
docker run -d -p 8888:80  --name nextcloud  -v ~/nextcloud/:/var/www/html/ --restart=always --privileged=true  arm64v8/nextcloud

安装完成后, 在电脑浏览器上访问: http://设备IP地址:8888, 即可查看nextcloud网盘页面。

8 参考资料

https://docs.docker.com/engine/install/debian/#install-from-a-package