The Raspberry Pi web.py rest service currently saves files to the folder /home/pi/data on the Docker container. This however is only available for the lifetime of the container. In practice this doesn't matter too much because the service is very stable but when I run updates for example I'd like the current list to persist.
Quick aside: Stopping a running container
(useful if I've left it running for 6 months)
First list the containers with docker ps
pi@raspberrypi:~/Server $ docker ps CONTAINER ID IMAGE ... NAMES 65cb45e19d62 rest-server ... loving_mirzakhani
We are interested in the Names column. In this case run
docker stop loving_mirzahkani
As per the documentation, volumes are the preferred way to persist data used by containers. So to set this up for the rest server I took the following steps.
Comment out the line to populate the image folder. We don't need to copy anything now so we can remove this line:
COPY data /home/pi/data/
(The data folder originally container start-up data for the webservice)
Then it's simply a case of rebuilding the image and running with this command, using the --mount syntax
docker run -d -p 8080:8080 --mount source=smktdata,target=/home/pi/data rest-server
The first time this was run it automatically created a volume called smktdata
The volume details can be shown with the command
docker volume inspect smktdata
pi@raspberrypi:~/Server $ docker volume inspect smktdata [ { "CreatedAt": "2019-07-05T18:14:50Z", "Driver": "local", "Labels": null, "Mountpoint": "/var/lib/docker/volumes/smktdata/_data", "Name": "smktdata", "Options": null, "Scope": "local" } ]
The Mountpoint is the location of the actual data. Files can be viewed with
sudo ls /var/lib/docker/volumns/smktdata/_data
I also have a NAS which is mounted automatically at startup. To use a folder on the NAS, I used this start-up command
docker run -d -p 8080:8080 -v /home/pi/NAS/data:/home/pi/data rest-server
Note that in this case I used the -v (--volume) syntax, this is equivalent to --mount. It essentially just combines all the options into a single field
No comments:
Post a Comment