Managing persistent storage with Docker involves the use of volumes, bind mounts, or tmpfs volumes on the host machine. Here is how to do it:
1. Volumes: Volumes are the most used mechanism for managing data in Docker. These are easy to use and can be shared among different containers. You can manage volumes using Docker CLI or Docker API.
To create a volume, use the command `docker volume create my-volume`.
To mount the volume in a container, specify it with ‘-v’ when running the container `docker run -v my-volume:/usr/local/data my-image`.
In this command, ‘my-volume’ is the name of your volume, ‘/usr/local/data’ is the path where you will mount the volume in your container and ‘my-image’ is the name of your Docker image.
To remove a volume, use `docker volume rm my-volume`.
1. Bind mounts: Bind mounts are essentially mapping the host file or directory to the container file or directory. They are dependent on the structure of the host file system.
To use bind mounts, when running your container specify host’s absolute path before the ‘:’ and the container’s destination path after, like this: `docker run -v /home/user/mydata:/usr/local/data my-image`
Again, ‘/home/user/mydata’ is the host’s directory, ‘/usr/local/data’ is where in the container the directory will be visible, and ‘my-image’ is your Docker image.
1. tmpfs mounts: tmpfs mounts are stored in the host system’s memory only, and are never written to the host system’s filesystem.
To use tmpfs mount, use ‘—tmpfs’ option like: `docker run —tmpfs /usr/local/data my-image`
In this case ‘/usr/local/data’ will be the path in your container where the tmpfs volume would be mounted, ‘my-image’ is your Docker image.
Remember to choose the right type of persistent storage depending on the nature of your application and data. All these mounts can be further managed and inspected using Docker CLI or Docker API.