I took a step back and realized that I could achieve the desired behavior much more easily by writing the changes to a temporary file locally and copying the file into the docker container:
with open(file, 'w+') as f:
f.write(extracted_data)
subprocess.run(['docker', 'cp', f'{file}', f'{self.container.id}:{self.repository_work_dir}/{file}'])