[英]Docker-Compose Output File To Local Host
I have the below docker-compose.yaml
file that sets up a database and runs a python script我有以下docker-compose.yaml
文件,它设置数据库并运行 python 脚本
version: '3.3'
services:
db:
image: mysql:8.0
cap_add:
- SYS_NICE
restart: always
environment:
- MYSQL_DATABASE=test_db
- MYSQL_ROOT_PASSWORD=xxx
ports:
- '3310:3310'
volumes:
- db:/var/lib/mysql
py_service:
container_name: test_py
build: .
command: ./main.py -r compute_init
depends_on:
- db
ports:
- 80:80
environment:
DB_HOST: db
DB_PORT: 3306
DB_USER: root
DB_PASSWORD: xxx
DB_NAME: test_db
links:
- db
volumes:
- py_output:/app/output
volumes:
db:
driver: local
py_output:
To run it I perform the following要运行它,我执行以下操作
docker-compose build
docker-compose up
docker-compose run -v /home/ubuntu/docker_directory/output:/app/output/* py_service
Here is the Dockerfile这是 Dockerfile
FROM python:3.7
RUN mkdir /app
WORKDIR /app
COPY env/requirements.txt requirements.txt
RUN pip install -r requirements.txt
COPY . .
CMD ["python3","main.py","-r","compute_init"]
Now this works fine I can see the data has been properly populated under the generated in the msql database.现在这工作正常我可以看到数据已在 msql 数据库中生成的下正确填充。 The python file at the end of the script should dump a csv file to /app/ouput/output.csv
(via pandas library df.to_csv("output/output.csv")
) My question is, how to recover that csv from the container to the local directory.脚本末尾的 python 文件应该将 csv 文件转储到/app/ouput/output.csv
(通过熊猫库df.to_csv("output/output.csv")
)我的问题是,如何从容器到本地目录。 The script seems to finish off without any errors, but can't find the output file at the end.该脚本似乎没有任何错误就完成了,但最后找不到输出文件。
似乎使用docker-compose run -v $(pwd)/output:/app/output py_service
完成了这项工作
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.