I am new to Rancher and Docker and I am having trouble getting my data to persist.
What I have done so far is using Rancher/Cattle I have created an EC2 server via the UI and have ran the below docker-compose.yml file and it successfully activates the mysql service.
What I am expecting is that, once the stack/service is running, any file written to dir /var/lib/mysql inside the container will be persisted even if the stack/service has been removed. I expect that I should be able to find the file on the EC2 server. Is this a correct assumption?
I can confirm that when I stop the service via the Rancher UI, any files that I added are persisted once I restart the service and log into the container. However when I remove the stack and rebuild it on the same host using the same docker-compose.yml file, those files have been removed.
version: '2'
services:
mysql:
container_name: flask_mysql
restart: always
image: mysql:latest
environment:
MYSQL_ROOT_PASSWORD: 'test_pass' # TODO: Change this
MYSQL_USER: 'test'
MYSQL_PASS: 'pass'
volumes:
- my-datavolume:/var/lib/mysql
volumes:
my-datavolume:
driver: local
Any suggestions?
You've defined a stack-scoped volume, which is tied to that particular stack and removed when you delete the stack. If you want it to live outside of the stack you need an environment-scoped volume: http://rancher.com/docs/rancher/v1.6/en/cattle/volumes/#environment-scoped-volumes