I have the below docker-compose.yaml
file that sets up a database and runs a python script
JavaScript
x
37
37
1
version: '3.3'
2
services:
3
db:
4
image: mysql:8.0
5
cap_add:
6
- SYS_NICE
7
restart: always
8
environment:
9
- MYSQL_DATABASE=test_db
10
- MYSQL_ROOT_PASSWORD=xxx
11
ports:
12
- '3310:3310'
13
volumes:
14
- db:/var/lib/mysql
15
py_service:
16
container_name: test_py
17
build: .
18
command: ./main.py -r compute_init
19
depends_on:
20
- db
21
ports:
22
- 80:80
23
environment:
24
DB_HOST: db
25
DB_PORT: 3306
26
DB_USER: root
27
DB_PASSWORD: xxx
28
DB_NAME: test_db
29
links:
30
- db
31
volumes:
32
- py_output:/app/output
33
volumes:
34
db:
35
driver: local
36
py_output:
37
To run it I perform the following
JavaScript
1
4
1
docker-compose build
2
docker-compose up
3
docker-compose run -v /home/ubuntu/docker_directory/output:/app/output/* py_service
4
Here is the Dockerfile
JavaScript
1
12
12
1
FROM python:3.7
2
3
RUN mkdir /app
4
WORKDIR /app
5
COPY env/requirements.txt requirements.txt
6
7
RUN pip install -r requirements.txt
8
9
COPY . .
10
11
CMD ["python3","main.py","-r","compute_init"]
12
Now this works fine I can see the data has been properly populated under the generated in the msql database.
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.
The script seems to finish off without any errors, but can’t find the output file at the end.
Advertisement
Answer
it seems using docker-compose run -v $(pwd)/output:/app/output py_service
did the job