We do all our development in containers, and one of our applications manages docker via docker-py in production. So testing becomes docker-ception (docker in docker). We mount the host docker.sock via compose for development (ie mount the volume /var/run/docker.sock:/var/run/docker.sock
which docker-py uses directly.
Many tests use the tmp_path
pytest fixture (or library-specific temp paths) and those tests fail with a collection of random errors - mostly file not found, module not found etc.
Running the same procedures by hand and outside the dev container work.
Why come?
TLDR
the
/tmp
folder needs to be mounted as a volume in the dev environment. addingmakes the temporary assets from testing available to the child container.
Long-winded answer
Docker-in-docker using the host
docker.sock
creates the containers as siblings, not nested children. This means the docker filesystem references from parent->child won't work because they are accessing the same filesystem as the host.When Debugging
main.py
did not actually mount, there will be amain.py
directory in the container.