[英]Docker with python to copy file specified, unzip and do actions
FROM python:3
ADD src/main.py /
RUN chmod +x main.py
RUN /usr/local/bin/python -m pip install --upgrade pip
COPY . /opt/app
RUN pip install -r /opt/app/requirements.txt
ADD / /usr/local
ENTRYPOINT [ "python", "./main.py" ]
if __name__ == '__main__':
if len(sys.argv) == 2:
main(sys.argv[1])
def main(logs_file_archive):
unzip_logs(logs_file_archive) # unzips all logs from the provided path to the folder with the same name as archive/Extracted directory
create_csv_files() # creates CSV files needed to plot graph
process_files() # populate CSV files generated with the right data
plot(logs_file_archive) # build this data representation
實際:
2022-01-17T22:05:31.547047838Z File "//./main.py", line 214, in <module>
2022-01-17T22:05:31.547210046Z main(sys.argv[1])
2022-01-17T22:05:31.547259438Z File "//./main.py", line 187, in main
2022-01-17T22:05:31.547670294Z unzip_logs(logs_file_archive)
2022-01-17T22:05:31.547732344Z File "//./main.py", line 54, in unzip_logs
2022-01-17T22:05:31.548296998Z with zipfile.ZipFile(file_path, "r") as zip_ref:
2022-01-17T22:05:31.548350898Z File "/usr/local/lib/python3.10/zipfile.py", line 1240, in __init__
2022-01-17T22:05:31.549638566Z self.fp = io.open(file, filemode)
2022-01-17T22:05:31.549692977Z FileNotFoundError: [Errno 2] No such file or directory: '/Users/user/PerfReader/misc/archive.zip'
No such file or directory: '/Users/user/PerfReader/misc/archive.zip'
應該很好......因為 Docker 機器中沒有這樣的文件。
期望:容器使用Dockerfile運行,數據處理,plot實時顯示或保存為文件並傳輸到主機
matplotlib.pyplot.savefig
將其傳輸回主機? 有多種方法可以訪問主機文件。 您可以使用copy
或add
命令,就像您在 Docker 文件中所做的那樣,該文件將在構建映像期間被復制。 此外,您可以使用綁定掛載,它允許您訪問已綁定的主機目錄,就像您在此目錄中運行容器一樣。
Docker 不支持 GUI 或訪問主機顯示。 但是,您可以使用Xauth
允許它這樣做。 請考慮以下鏈接的步驟。
無論哪種方式,我都不鼓勵將 Docker 用於您正在做的事情,尤其是繪圖部分,python 虛擬環境就綽綽有余了。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.