I have tried the command but was afraid if it would remove the main container if it has stopped due to the memory full. Please can you advise if it would not delete the main container?
Yes, the command would indeed remove any stopped container. Why would this be a problem? A docker container should never hold any persistent data itself, but rely on e.g. mounted volumes instead. Apart from that, tools like Docker Compose can be used to describe containers to allow creating and destroying them at any time.
Maybe try using the du command to find files/directories on your system that take a significant amount of disk space. E.g. you could try to remove some logs or cache files in order to free up at least some megabytes.