检索由docker python程序编写的.csv文件

时间:2018-09-23 14:41:51

标签: python docker

我正在尝试访问dockerized python程序正在制作的.csv文件。

这是我的docker文件:

# Use an official Python runtime as a parent image
FROM python:3.7

# Set the working directory to /app
WORKDIR /BotCloud

# Copy the current directory contents into the container at /app
ADD . /BotCloud

# Install any needed packages specified in requirements.txt
RUN pip install --trusted-host pypi.python.org -r requirements.txt

RUN wget http://prdownloads.sourceforge.net/ta-lib/ta-lib-0.4.0-src.tar.gz && \
  tar -xvzf ta-lib-0.4.0-src.tar.gz && \
  cd ta-lib/ && \
  ./configure --prefix=/usr && \
  make && \
  make install

RUN rm -R ta-lib ta-lib-0.4.0-src.tar.gz

RUN pip install ta-lib

# Run BotFinal.py when the container launches
CMD ["python","-u", "BotLiveSnake.py"]

这是我的python文件BotSnakeLive.py中的代码段

def write(string):
    with open('outfile.csv','w') as f:
        f.write(string)
        f.write("\n")
write(str("Starting Time: "+datetime.datetime.utcfromtimestamp(int(df.tail(1)['Open Time'])/10**3).strftime('%Y-%m-%d,%H:%M:%SUTC'))+",Trading:"+str(pairing)+",Starting Money:"+str(money)+",SLpercent:"+str(SLpercent)+",TPpercent,"+str(TPpercent))

在本地运行我的python程序,将在与我的python程序相同的文件夹中创建outfile.csv。但是,对于docker,我不确定此文件的结束位置。任何帮助,将不胜感激。

1 个答案:

答案 0 :(得分:0)

通常,对并非以take(250000, 750000)开头的文件路径的引用始终相对于当前工作目录进行解释。除非您进行了某种更改(/,这是一个运行os.chdir的入口点脚本,它是cd选项),否则它将成为您在docker run -w中声明的WORKDIR

因此:您的文件应该位于容器文件系统空间的Dockerfile中,

请注意,容器具有自己的隔离文件系统空间,该空间在删除容器时会被破坏。如果您的应用程序进行通信的主要方式是通过文件,则使用非Docker机制(例如Python虚拟环境)将您的应用程序与系统的其余部分隔离起来可能会容易得多。您可以使用/BotCloud/outfile.csvdocker run -v文件将主机目录装入容器。 (特别注意docker cp,如果将数据写入与应用程序不是同一目录的某个位置,则将很有帮助。)