E.g., for me, the following Dockerfile:
FROM python:3 RUN pip3 install ipdb COPY test.py /test.py CMD ["python", "test.py"]
import ipdb; ipdb.set_trace() print('Hello, World.')
» docker run -ti --rm 52e98c118dc3 > /test.py(2)<module>() 1 import ipdb; ipdb.set_trace() ----> 2 print('Hello, World.') ipdb> p globals() {'__name__': '__main__', '__doc__': None, '__package__': None, '__loader__': <_frozen_importlib_external.SourceFileLoader object at 0x7f809a8c8278>, '__spec__': None, '__annotations__': {}, '__builtins__': <module 'builtins' (built-in)>, '__file__': 'test.py', '__cached__': None, 'ipdb': <module 'ipdb' from '/usr/local/lib/python3.7/site-packages/ipdb/__init__.py'>} ipdb> ^D Exiting Debugger. »
`docker exec -e foo=bar -it ....`
E.g., for me, the following Dockerfile:
where test.py is: run as `docker run -ti --rm $IMAGE_ID` works as expected: