Using volumes is the best way of handling data which you want to keep from a container. Using the -v
flag works well and you shouldn't run into issues with this.
You can also use the VOLUME
instruction in the Dockerfile
which means you will not have to add any more options at run time, however they're quite tightly coupled with the specific container, you'd need to use docker start
, rather than docker run
to get the data back (or of course -v
to the volume which was created in the past, likely in /var/
somewhere).
A common way of handling volumes is to create a data volume container with volumes defined by -v
Then when you create your app container, use the --volumes-from
flag. This will make your new container use the same volumes as the container you used the -v
on (your data volume container). Of course this may seem like you're shifting the issue somewhere else.
This makes it quite simple to share volumes over multiple containers. Perhaps you have a container for your application, and another for logstash.