How to connect Emacs' Elpy in-buffer python interpreter to docker container?

Why is codecs.py trying to read a tmp file?

I'm pretty sure this is what's happening:

  1. Emacs writes code to /tmp/py10324GOe
  2. Emacs instructs Python to load /tmp/py10324GOe
  3. Python fails because the container cannot access the host's /tmp/. The container has its own, separate /tmp/ directory.

The simplest way to fix this would be to link the host's /tmp/ directory to the container's /tmp/ directory. Some googling leads me to a command like:

docker run ... -v /tmp:/tmp

I haven't tested that code, but it seems like the right direction.