Dockerfile unable to locate file bundled with Pyinstaller

Hello, I have been stuck on this issue for a couple days now and finally decided to reach out to Docker community forums.

I wrote a program. The program builds a docker image and runs it in a container. Everything works great!

When I bundle the program together with Pyinstaller, I call --add-data on my Dockerfile so that it is included with the bundle (gets placed in _internal, right next to the executable). That all works great!

When I run the executable, the program finds the Dockerfile no problem! However, it cannot find a file that was previously found before I had bundled the program with pyinstaller.

The Dockerfile copies an nginx.config.template file to /usr/local/nginx/conf/nginx.conf.template. This works fine when I am running the program before bundling it with Pyinstaller, but when I create the executable with pyinstaller, it can no longer find this file.

I have tried to call --add-data on my nginx.config.template file, and it even shows up in _internal, right next to the Dockerfile! But, what I suspect is the Docker context has no awareness of this file. I have no idea how to get it to be aware of this file. I have placed an nginx.config.template file in nearly every directory in my project and no matter where it is, Dockerfile keeps failing on building because it cannot find it.

This seems like it would be an extremely common issue, but nowhere online have I found the solution. I do not have a .dockerignore file. It looks like it gets generated when it tries to build, but I don’t have one before building.

I believe I found my issue.

My build command needed to be given the correct context. I still don’t really understand where the context is after my Dockerfile gets bundled. I believe it is coming from within the _internal forlder (where Dockerfile ends up).

After I explicitly passed in the context by getting the executable directory (executable_dir = os.path.dirname(os.path.abspath(file)), my build command looked like this:

os.system(f'docker build -f {dockerfile_path} -t multi-stream-tool {executable_dir}')

And works both before being bundled and after.