I know maybe this isn't the answer you are expected but I have a different docker compose file for each project. Once I've finished working on one project I
docker-compose down -v project, switch to my working copy in my other project and
docker-compose up -d
Each project has it's own set of containers which build up a lamp stack. So own db container. But also that way I've got plenty of resouce free for IDE etc
But also that way you're not having to make config changes to switch between stacks. Plus they can all have same url (magento2.docker) and I've got 1 host file entry. Lazy but as docker is dev for me it's okay to take shortcuts.
And file like this for each project