I have a basic Python Docker container that uses the O365 library to retrieve mail from Office365.

FROM python:3
ADD requirements.txt ./
RUN pip install -r requirements.txt
ADD ./main ./main
CMD [ "python", "./main/main.py"]

The first time you run this O365 library, you need to authorize it and it stores a o365_token.txt which it uses after that. That looks like this:

Visit the following url to give consent:
Paste the authenticated url here:

This also happened on my new Docker so I logged in to it through Bash:

docker run -it hvdveer/e2t-python bash

But now when I manually run it, it just utilizes the existing token and it works without verification. Deleting the token files and authorizing it again also doesn't work. Why does it ask for authorization when I run it automatically, but not when run it manually? Are these different users? How to I fix this?

1 Answers

Herman On

I fixed it!

The CMD is run from the root directory so it's looking for the token there. By changing the WORKDIR to the main of my program it now finds the token:

FROM python:3
ADD requirements.txt ./
RUN pip install -r requirements.txt
ADD ./main .
CMD [ "python", "./main.py"]

That still didn't explain why running it from root by hand and creating a token in root didn't solve the problem, but it turns out those changes aren't saved. Apparently every time you close the image it forgets everything. Live and learn.