Running subprocesses for docker operations is cumbersome. Use a lib instead, e.g. https://github.com/gabrieldemarmiesse/python-on-whales