Prevent orphan in docker rmi

Closes #3258

Doesn't completely solves some `docker rmi` edge cases, but at least prevent orphan.