
Docker volumes
I spent more time than I care to admit trying to get a docker volume to work with an InfluxDB (version 3) container. I was using someone else’s starting point that worked on their machine and a server they setup by hand, but I could not get it working on my machine. I am still not 100% sure what the difference is but I at least got it working.
Normally when I want a docker volume so I can save state between container runs I use
docker run -v $(pwd)/data:/some/location/in/container ...
Tonight I learned that this is not technically a docker volume but instead is actually called a “bind mount”. Bind mounts have their place, especially for development scenarios where you want to update code inside the container. But apparently this solution is less performant and not recommended in production scenarios for a variety of reasons (performance and security being the two that stood out to me).
Instead we apparently should be creating a legit docker volume with
docker volume create my-volume
and then instead of pointing to a directory when you run the container you just give the name of the volume and otherwise it works the same as before.
docker run -v my-volume:/some/location/in/container ...
The files are still stored on the docker host, but just in a separate directory that’s owned/managed by docker (ie the host root user). The volume can be found on an ubuntu based system here:
/var/lib/docker/volumes/my-volume/_data/
So you could still create a cronjob as the root user to do backups as needed, zip/tar the directory containing the volume data and send it off to s3 or other data storage.