Error when opening a LUKS encrypted container file /dev/loop0 Device or resource is busy on Ubuntu 18.10 Gnome Desktop

When you enter the command below in a terminal window:

$ sudo /sbin/losetup /dev/loop0 /home/user1/folder1/containerdatafile <enter>

Device error or resource busy error message appears and the device is not setup.

The reason is that /dev/loop0 is taken by snap.

To overcome the error, change /dev/loop0 to something else like /dev/loop35

Or, if you do not use snap, remove snap by:
$ sudo apt-get purge snap snapd <enter>

Now you can check if the /dev/loop0 is taken by snapd by typing:
$ df <enter>

There should be no more loop0 device used by snap and the original command should work with /dev/loop0.