I'm using the https://github.com/lukechilds/dockerpi project to recreate a Raspberry Pi locally with Docker. However, the default disk space is very small and I quickly fill it up:
pi@raspberrypi:~$ df -h
Filesystem Size Used Avail Use% Mounted on
/dev/root 1.8G 1.2G 533M 69% /
devtmpfs 124M 0 124M 0% /dev
tmpfs 124M 0 124M 0% /dev/shm
tmpfs 124M 1.9M 122M 2% /run
tmpfs 5.0M 0 5.0M 0% /run/lock
tmpfs 124M 0 124M 0% /sys/fs/cgroup
/dev/sda1 253M 52M 201M 21% /boot
tmpfs 25M 0 25M 0% /run/user/1000
How can I give move space to the RPi? I saw this issue, but I don't understand how that solution is implemented, or if it is relevant.
In the current Docker version, there is a default limitation on the Docker container storage of 10Gb. As the BlazeMeter image is ~5 GB when the sample.
Docker takes a conservative approach to cleaning up unused objects (often referred to as “garbage collection”), such as images, containers, volumes, and networks: these objects are generally not removed unless you explicitly ask Docker to do so. This can cause Docker to use extra disk space.
All you can find on the host machine is the single huge Docker. raw file which is reported to be 60GB (allocated size of the file, tells the maximum potential disk size which can be used), but actually taking 22GB in terms of how many bytes are actually consumed by the file on the file system right now.
Docker Raspberry Pi 4 Raspberry Pi 4 can work as a low-cost Docker resolution for application development and various responsibilities. It has the latest 8GB version. A Raspberry Pi 4 is a single-board processor.
There are two methods to make images smaller. One is quite brutal but easy and efficient. Second is more tedious but defiantly more agile and robust. The easy one is simply to export the image with Docker and later import it. The more complicated one is more like doing the whole flow. This process will create a flattened image.
Assuming you are using Debian. Remove the main and swap partitions (leaving the boot partition alone) Recreate the main partition to utilize the remaining disk space (excluding the boot partiton). Make sure to reuse the same start sector as the original root partition. resize the new boot root partition to utilize the full partition size.
The default basesize of a Docker container, using devicemapper, has been changed from 10GB to 100GB. Here is a link to the corresponding pull request in github. Current default basesize is 10G.
We can see all the layers for the original ubuntu image, and then ours on top. If we keep adding, deleting, and changing files to images with a commit, our image will grow in size. An important bit is that size of the image is a sum of all its layers.
To increase the disk size, you need to extend the partition of the qemu disk used inside the container.
Start the docker to unzip rootfs and mounted it to an host path
docker run --rm -v $HOME/.dockerpi:/sdcard -it lukechilds/dockerpi
When the virtualized raspberry is up, you can stop it, running from the docker prompt sudo poweroff
Then you have the qemu disk in $HOME/.dockerpi/filesystem.img
.
It could be extended with :
sudo qemu-img resize -f raw $HOME/.dockerpi/filesystem.img 10G
startsector=$(fdisk -u -l $HOME/.dockerpi/filesystem.img | grep filesystem.img2 | awk '{print $2}')
sudo parted $HOME/.dockerpi/filesystem.img --script rm 2
sudo parted $HOME/.dockerpi/filesystem.img --script "mkpart primary ext2 ${startsector}s -1s"
Restart the raspberry that will use the resized qemu disk with :
docker run --rm -v $HOME/.dockerpi:/sdcard -it lukechilds/dockerpi
Running from the docker prompt you can extend the root filesystem with :
sudo resize2fs /dev/sda2 8G
Finally the root is increased.
Following this df -h
give :
Filesystem Size Used Avail Use% Mounted on /dev/root 7.9G 1.2G 6.4G 16% / devtmpfs 124M 0 124M 0% /dev tmpfs 124M 0 124M 0% /dev/shm tmpfs 124M 1.9M 122M 2% /run tmpfs 5.0M 0 5.0M 0% /run/lock tmpfs 124M 0 124M 0% /sys/fs/cgroup /dev/sda1 253M 52M 201M 21% /boot tmpfs 25M 0 25M 0% /run/user/1000
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With