简体   繁体   English

如何使用Docker创建Python可执行文件

[英]How to create a Python executable using Docker

I have a running python executable EIA.py which extracts information from EIA.gov website and downloads necessary information into an excel file on my laptop's C:/Python Folder. 我有一个正在运行的python可执行文件EIA.py,该文件可从EIA.gov网站提取信息并将必要的信息下载到笔记本电脑的C:/ Python文件夹中的excel文件中。 However, when I convert this file into image and run using docker run command for image it gives me following error. 但是,当我将此文件转换为图像并使用docker run命令运行图像时,出现以下错误。

FileNotFoundError: [Errno 2] No such file or directory: 'C:/Python/Sid.xls' FileNotFoundError:[错误2]没有这样的文件或目录:'C:/Python/Sid.xls'

I am not adding any file but Python should rather create an excel file with contents extracted from website. 我没有添加任何文件,但是Python应该使用从网站提取的内容来创建一个excel文件。

Following is my code from Dockerfile 以下是我来自Dockerfile的代码

 FROM python
 VOLUME ["C:/Sid"]
 WORKDIR /app
 COPY . /app
 RUN pip install EIA-python
 RUN pip install requests
 RUN pip install pandas
 RUN pip install xlwt
 RUN python /app/EIA.py

Following is my python code 以下是我的python代码

 import eia
 import pandas as pd

 api_key = "mykey"
 api = eia.API(api_key)

 series_storage = api.data_by_series(series='NG.NW2_EPG0_SWO_R48_BCF.W')
 df1 = pd.DataFrame(series_storage)
 df1.reset_index(inplace=True)
 df1.columns = ['Date', 'Value']
 df1['Date'] = pd.to_datetime(df1['Date'].str[:-3], format='%Y %m%d')
 df1.to_excel("C:/Python/Sid.xls")

Docker containers do not have persistent storage. Docker容器没有持久性存储。 To save a file locally from a container, you can either bind a folder mount or create a docker volume. 要从容器本地保存文件,可以绑定文件夹安装或创建docker卷。 Docker volumes are the preferred mechanism for persisting data as they are completely managed within Docker CLI itself. Docker卷是用于持久化数据的首选机制,因为它们是在Docker CLI本身中完全管理的。 Check out here for more info. 此处查看更多信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用 Docker 运行多个 Python 脚本和一个可执行文件? - How to run multiple Python scripts and an executable files using Docker? 使用setuptools创建python可执行文件 - Create a python executable using setuptools 如何使用python代码创建Linux可执行文件 - How to create a Linux executable file using python code 如何使用 Hy 模块创建 Python 独立可执行文件? - How can I create a Python standalone executable using Hy modules? 如何使用python tkinter可执行文件创建Word文档? - How to create a word document using a python tkinter executable? 使用py2exe,如何使用python和tkinter创建可执行文件? - Using py2exe, how to create an executable usng python and tkinter? 在 python 中使用子进程时如何创建独立的可执行文件? - How to create standalone executable when using subprocess in python? 使用python setuptools创建Windows可执行文件 - Create windows executable using python setuptools 如何在 Intel Edison 上创建可执行的 Python 代码? - How to create executable Python code on Intel Edison? 如何使用 Selenium 和 chromedriver 创建 Python 可执行文件? - How to create a Python executable with Selenium and chromedriver?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM