Ditch the single use containers and get a (reusable) spray foam gun, matching container(s) and cleaner(s).
Spray foam container goes on the gun, use, remove container from gun and replace with container containing the cleaner. Spray until only clear cleaning solvent comes out. Put spray cap on cleaning container, clean top of spray foam container, connector of spray gun and if necessary also the outer surfaces of the gun. (Cleaner can be used to clean fresh foam from other tools, hands, clothing as well ... But just be aware that this stuff, like so many others, is not exactly a "healthy" choice to clean hands and a regular hand wash + some moisturizer is highly recommended afterwards.)
There are tubes and other accessories for the gun if needed. When using tubes, do not solely rely on the threading of the guns nozzle, use some tape to secure it and beforehand adjust pressure. They love to burst off.
Pictured is my spray foam gun and the two containers (1x foam, 1x cleaner) I'm currently using. As you can see, totally clean, ready for use. You might notice the "A" I wrote on both containers, my way of identifying open/in-use containers in storage or my workshop.

Kind regards,
Oliver