Apparently this is happening when we make a switch rebuild with running containers.
The solution would be to stop the containers before switching, using docker stop $(docker ps -q)
Additionally, best practice when switching off computer, use sudo shutdown -r now
instead of sudo reboot
to avoid corrupt any volume.
In case you are embedding your commands to upgrade or install the system in a shell script, you might find useful a kind of hook, so before switching nix, check if containers are running.
You can find the script to handle docker in my repo
I call the script from install.sh or upgrade.sh
And I only update the system using these scripts so I have more control and don’t forget any checkup