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

From FriendlyELEC WiKi
Jump to: navigation, search
(updated by API)
 
(updated by API)
Line 2: Line 2:
 
====Pre-installation checks and preparations====
 
====Pre-installation checks and preparations====
 
Docker now recommends using the Overlay2 storage driver, but it may not be able to be installed directly because the root file system is already using OverlayFS. Some adjustments need to be made to the partition. There are two methods:<br />
 
Docker now recommends using the Overlay2 storage driver, but it may not be able to be installed directly because the root file system is already using OverlayFS. Some adjustments need to be made to the partition. There are two methods:<br />
Method 1) Make the root file system no longer use OverlayFS (disadvantage: the factory reset function will not work);<br />
+
;Method 1
Method 2) Keep using OverlayFS for the root file system and create an additional partition for storing Docker data.<br />
+
: Make the root file system no longer use OverlayFS (disadvantage: the factory reset function will not work);<br />
 +
;Method 2
 +
: Keep using OverlayFS for the root file system and create an additional partition for storing Docker data.<br />
 
The following will explain these two methods separately, please choose one according to your needs.<br />
 
The following will explain these two methods separately, please choose one according to your needs.<br />
 
<br/>
 
<br/>
Line 10: Line 12:
 
Note 2: You need to update the firmware to a version on or after March 14, 2023, or update the boot.img separately.<br>
 
Note 2: You need to update the firmware to a version on or after March 14, 2023, or update the boot.img separately.<br>
 
Note 3: The device node /dev/mmcblkX mentioned in the command is a fictional node and needs to be changed to the real device. The device node for eMMC is /dev/mmcblk2, and for TF card is /dev/mmcblk0.<br>
 
Note 3: The device node /dev/mmcblkX mentioned in the command is a fictional node and needs to be changed to the real device. The device node for eMMC is /dev/mmcblk2, and for TF card is /dev/mmcblk0.<br>
<br/>
 
 
====Method 1: Make the root file system not use OverlayFS====
 
====Method 1: Make the root file system not use OverlayFS====
 
* Write specific content to /.init_wipedata and reboot:
 
* Write specific content to /.init_wipedata and reboot:

Revision as of 11:25, 16 March 2023

查看中文

1 Pre-installation checks and preparations

Docker now recommends using the Overlay2 storage driver, but it may not be able to be installed directly because the root file system is already using OverlayFS. Some adjustments need to be made to the partition. There are two methods:

Method 1
Make the root file system no longer use OverlayFS (disadvantage: the factory reset function will not work);
Method 2
Keep using OverlayFS for the root file system and create an additional partition for storing Docker data.

The following will explain these two methods separately, please choose one according to your needs.

Precautions:
Note 1: This operation will erase user data, so it is necessary to backup data in advance.
Note 2: You need to update the firmware to a version on or after March 14, 2023, or update the boot.img separately.
Note 3: The device node /dev/mmcblkX mentioned in the command is a fictional node and needs to be changed to the real device. The device node for eMMC is /dev/mmcblk2, and for TF card is /dev/mmcblk0.

2 Method 1: Make the root file system not use OverlayFS

  • Write specific content to /.init_wipedata and reboot:
sudo passwd root  # Create a password for the root user if it hasn't been done before.
su - root -c 'echo "overlayfs=disable" > /.init_wipedata'
sudo reboot
  • After rebooting, use the parted command to view the current partition layout. Normally, you should see that the root system is mounted in ext4 format, not overlay as before:
sudo apt update
sudo apt install parted
export DEV=/dev/mmcblkX
sudo parted -s ${DEV} unit MiB print

3 Method 2: Create an additional partition for Docker

  • Check the current partition layout
sudo apt update
sudo apt install parted fdisk
export DEV=/dev/mmcblkX
sudo parted -s ${DEV} unit MiB print
  • Adjust the userdata partition to 8GB

Here, 8GB is used as an example. The partition size can be adjusted according to your needs:

sudo passwd root  # Create a password for the root user
su - root -c 'echo "overlayfs=enable userdata=8096" > /.init_wipedata'
sudo reboot

After reboot, confirm that the partition has been adjusted and you can see that the userdata partition is now 8GB:

sudo parted -s ${DEV} unit MiB print
  • Create a new partition and format it:
(echo n; echo ""; echo ""; echo ""; echo w) | sudo fdisk ${DEV}
NUM=$(sudo parted ${DEV} print | awk 'NF > 1 {p = $1} END {print p}')  # Get the index of the last partition
sudo mkfs.ext4 ${DEV}p${NUM}
  • Mount the partition to the Docker data directory:
sudo mkdir /var/lib/docker
sudo blkid ${DEV}p${NUM}
# Configure automatic mounting
sudo vi /etc/fstab
# Add the following content to the end of the file (where UUID needs to be replaced with the actual one).
UUID=2efab5a5-8b74-41d2-8747-4c00fff8514a /var/lib/docker ext4 suid,dev,exec,auto,nouser,async,noatime,nofail 0 0
sudo mount /var/lib/docker

4 Install Docker Engine

  • The docker installer uses iptables for nat, unfortunately Debian uses nftables, here we just setup Debian to use the legacy iptables:
command -v nft &> /dev/null && sudo update-alternatives --set iptables /usr/sbin/iptables-legacy
command -v nft &> /dev/null && sudo update-alternatives --set ip6tables /usr/sbin/ip6tables-legacy
  • Start installing Docker:
sudo apt install curl ca-certificates uidmap
curl -fsSL https://get.docker.com | bash

Verify if Docker has been installed successfully:

sudo docker info

Check if it is using the overlay2 storage driver.:

$ docker info | grep storage -i
 Storage Driver: overlay2

5 Run Docker as a non-root user

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

Let’s verify:

docker images

6 Testing Docker: Installing Nextcloud with docker

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

After installation, visit: http://Device-IP-Address:8888 on your computer browser to view the nextcloud web page.