What directories of a running system can I exclude from tarball when creating image

I write an image of the raspberry pi 64-bit desktop version to an sd card.
Then I boot the system off of the sd card and issue a
tar --exclude lost+found --exclude mnt --exclude media --exclude tmp --exclude cvfz bullseye64fs.tgz / command to create a tarball.

Then I created a docker image using the following docker file, with docker build -t johncblacker/bullseye64-base . command:

FROM scratch

ADD /bullseye64fs.tgz ./

Next I perform a docker push johncblacker/bullseye64-prod to get the image on docker hub.

My next step was to use this base image to install the software for opencv, libcamera, picamera2, flask, waitress and gunicorn. This image could then be used for AI or another could be built using this image as a base and add tensorflow, for example.

My question is: are there additional directories that I can or should exclude from the tarball in order to get the base image size down further. When I look at the size of the image with opencv, flask, etc. that image is about 6gb. I’m thinking that’s large, but maybe given all the software installed in/on it perhaps it’s OK. I could some guidance. I thought of starting with the “non-desktop” version, but decided against it because I want the x-server and the ability to run gui apps in the container that’ll display on the original host rpi.

Why? What do you want to achieve?

I would like to keep the base image as small as I can.

Why do you want to create a container image from an installed operating system?

Containers are not VMs, so they mostly just contain applications, not OS.

What do you want to achieve?

1 Like

I agree with @bluepuma77 100 percent. Cloning your physical host is not the right way of creating base image. You can simply use an official base image from Docker Hub or download distributions from other sources. You can find some information in the documentation:

If you are just “playing” and expeimenting with containers want to convert a VM into a container out of curiousity, I still don’t recommend it, but here is what you need to know.

As @bluepuma77 suggested, a container is not a VM, which also means you don’t need a kernel in the container so the /boot folder is definitely something you wouldn’t want to copy. You could also have packages that you would never use in the container, like systemd, so converting an existing Linux installation to a container is not a good idea. Linux also has temoporary filesystems like /sys, /run, /var/run or there is also the /dev for devices which is a way to communicate with hardware

When creating a tarball image of a running system, certain directories should typically be excluded to ensure a more manageable and relevant archive. These exclusions often include /proc , /sys , /dev , and /tmp , as they contain dynamic and temporary data, which may not be needed for system backup or migration. Additionally, it’s advisable to exclude any user-specific data and large log files from /var/log to reduce the tarball’s size. Careful consideration of what’s essential for system restoration and what can be regenerated is crucial when making these exclusions.

I’m grateful for your kind words about the blog and for the chance to share my thoughts. Your support is truly appreciated, and I’m looking forward to your ongoing engagement with my upcoming posts. Thank you for acknowledging my efforts, and I’m enthusiastic about delivering more valuable content in the days to come.

mod update: removed advertisement link.