Docker未将输出保存到fi

2024-04-19 10:16:34 发布

您现在位置:Python中文网/ 问答频道 /正文

最初是关于这个主题的this。应答后,csv被保存到指定的目录。不会有一个新的目录(/ll)但是现在没有了。我不知道为什么这样不行了。如果没有docker,python脚本将按预期运行。在

我运行的命令:

docker build -t dock ./search_api
docker run -v ~/twitter-data/data:/app/ dock

得到以下输出:

^{pr2}$

这是Dockerfile

# Use an official Python runtime as a parent image
FROM python:3.6-slim

# Set the working directory to /app
WORKDIR /search

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

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

# Run app.py when the container launches
CMD ["python", "search.py"]

在搜索.py正在附加到tweets.csv在


Tags: csvthedockerpy目录txtapp主题
2条回答

好的,这是因为卷是~/twitter-data/data,而search.py/app.pysearch_api目录中。谢谢你的帮助,很抱歉我没有告诉你所有的信息。在

twitter-data
├── CODE_OF_CONDUCT.md
├── CONTRIBUTING.md
├── LICENSE
├── README.md
├── __pycache__
│   └── config.cpython-36.pyc
├── ci
│   └── build-images.sh
├── data
│   └── tweets.csv
├── images
│   └── test
│       └── Dockerfile
└── search_api
    ├── Dockerfile
    ├── __pycache__
    │   └── config.cpython-36.pyc
    ├── app.py
    ├── config.py
    └── requirements.txt

绑定到容器中的错误目录。如果您收到的输出是Saved to /search/tweets.csv,那么您需要将挂载目录绑定到/search,而不是{}。在

到目前为止,您正在将目录/app从容器内部映射到主机,我认为即使在容器内,主机也是空的。在

要解决您的问题,只需将docker run命令更改为:

$ docker run -v ~/twitter-data/data:/search/ dock

相关问题 更多 >