I believe this is actually one of the ways that Docker actually implements things for their MacOS support, so it's already done for containerization type stuff. Though I don't believe that docker gives you any real access to the "host" that is sets up for doing this.
https://docs.docker.com/desktop/faqs/macfaqs/