In the past I have often booted my main operating system from different Macs, while my MacBook was in repair. Sometimes you may have to redo some of the settings, such as Network preferences. Also, restoring the recovery partition (see also below) can be annoying.
First you need to figure out if your iMac is compatible with the version of MacOS you are using. In case you use Mojave, compatible iMacs are: "iMac introduced in late 2012 or later" according to Apple's support page. In case your iMac is such a model, you should be fine.
I suggest you simply try it by cloning your macOS to an external USB SDD or HDD and boot from it.
- Clone the drive. I really like SuperDuper! which can be used for free. Alternatively, Carbon Copy Cloner (commercial) is also nice, because it can also clone and restore your hidden recovery partition. The recovery partition is not necessary for booting.
- Connect the USB drive to your iMac.
- Press the alt button before the startup sound.
- Select the USB drive.
Please make sure your USB drive is formatted with the GUID Partition Map, as this is required for booting external drives.