python docker中没有此类文件或目录

j91ykkif  于 2023-02-28  发布在  Python
关注(0)|答案(1)|浏览(213)

我有一个读取文件的python脚本,但是当我尝试将其移植到Docker容器时,它抛出了一个错误No such file or directory in python docker
Python:

for root, dirs, files in os.walk(r"//some/LogFiles$"):
        for filename in files:
            if "RSPowerBI" in filename:
                file = filename
    with open(fr'//some/LogFiles$/{file}') as fd:
        lines = fd.readlines()

停靠文件:

FROM python:3.10.7
RUN pip install --upgrade pip --default-timeout=100 future
WORKDIR /check
COPY . /check

RUN pip install  -r requirements.txt

CMD [ "python", "/check/errors.py" ]

对接-组合:

version: '3.1'

services:
  bot2:
    image: first3
    build: ./
    restart: always
    volumes:
      - //some/LogFiles$:/check/some/LogFiles$
laik7k3q

laik7k3q1#

尝试将Python脚本修改为:

import os

log_files_path = '/check/some/LogFiles$'

for root, dirs, files in os.walk(log_files_path):
    for filename in files:
        if "RSPowerBI" in filename:
            file_path = os.path.join(log_files_path, filename)
            if os.path.exists(file_path):
                with open(file_path) as fd:
                    lines = fd.readlines()
                    # process the file contents
            else:
                print(f"File not found: {file_path}")

相关问题