У меня есть скрипт Python, который создает текстовый файл. когда я запускаю скрипт python один, он работает нормально.
class TXT_file():
### initialize the txt_file class
def __init__(self, path2file):
self.path2file = path2file
with open(path2file, "w") as f:
f.write("")
### write sentence to the txt_file
def sentence_to_file(self, sentence):
with open(self.path2file, "w") as f:
f.write(sentence)
### function initiating the class file and writing "Hello world!"
def run_sequence(path2data, file):
### initialize the gps_file class
my_txt_file = TXT_file(path2data + file)
my_txt_file.sentence_to_file("Hello world!")
### main
if __name__ == "__main__":
### setting up paths to various data files
path2data = 'C:\\Users\\abc\\folder\\'
file = "example_text_file.txt"
run_sequence(path2data, file)
Когда я создаю образ докера с ним. Я установил Docker для Windows и используя контейнеры Windows. Dockerfile выглядит как
FROM python:3
ADD txt_file_creation.py /
CMD [ "python", "./txt_file_creation.py", " ./example_text_file.txt"]
Я не могу получить файл example_text_file.txt
в качестве вывода, и он выдает ошибку:
Я использую следующие команды для сборки и запуска образа Docker:
docker build -t test_print_1 .
docker run test_print_1
ошибка, которую я получаю:
Traceback (most recent call last):
File "./txt_file_creation.py", line 34, in <module>
run_sequence(path2data, file)
File "./txt_file_creation.py", line 26, in run_sequence
my_txt_file = TXT_file(path2data + file)
File "./txt_file_creation.py", line 15, in __init__
with open(path2file, "w") as f:
FileNotFoundError: [Errno 2] No such file or directory: 'C:\\Users\\abc\\folder\\example_text_file.txt'
Как мне распечатать файл в той же папке с докером.