How do people deal with persistent storage for your Docker containers?
I am currently using this approach: build the image, e.g. for PostgreSQL, and then start the container with
docker run --volumes-from c0dbc34fd631 -d app_name/postgres
IMHO, that has the drawback, that I must not ever (by accident) delete container "c0dbc34fd631".
Another idea would be to mount host volumes "-v" into the container, however, the userid within the container does not necessarily match the userid from the host, and then permissions might be messed up.
Note: Instead of --volumes-from 'cryptic_id'
you can also use --volumes-from my-data-container
where my-data-container
is a name you assigned to a data-only container, e.g. docker run --name my-data-container ...
(see the accepted answer)
There are several levels of managing persistent data, depending on your needs:
-v host-path:container-path
to persist container directory data to a host directory.--volumes-from
to mount that data into your application container.I'm just using a predefined directory on the host to persist data for PostgreSQL. Also, this way it is possible to easily migrate existing PostgreSQL installations to Docker containers: https://crondev.com/persistent-postgresql-inside-docker/