I have a problem. I have created my docker-compose and in it one of the service has a script written in python to backup the mysql database locally. I don't know how to make the script in the docker access the path '/var/lib/mysql/' on the host. To backup database I use:
subprocess.check_call(f"mysqldump -u phpmyadmin -pMyPassword MyDatabase > /var/lib/mysql/backups/MyDatabase/26_09_2022.sql.backup")
Could you help me? Should I use volume?
CodePudding user response:
Should I use volume?
Yes, volumes are the answer. Based on your example, it should look like this.
version: "3"
services:
your_service:
...other_config...
volumes:
- /var/lib/mysql:/var/lib/mysql
Or written out like this.
version: "3"
services:
your_service:
...other_config...
volumes:
- type: bind
source: /var/lib/mysql
target: /var/lib/mysql