[英]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文件。
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
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.