How to Create a Persistent
Application in Three Steps or Less
Now that we’ve covered how to Provision Persistent Volumes In One Easy Step, it’s time to put those volumes to use. Our software package features a Docker plugin that integrates our volumes seamlessly into the Docker experience.
This blog covers how to utilize the integration most effectively, and provides examples of persistent storage in container applications.
Explicit Volume Creation
It should be noted that while you CAN use the –node flag, it’s not necessary as the CIO Orchestration system will automatically move the volume to where it is needed.
Now that we have a volume, we can use it with Docker. Here’s an example of using the Storidge volume as the basis for a persistent container:
docker run --name postgres \ -e POSTGRES_PASSWORD=mysecretpassword \ -v postgres-data:/var/lib/postgresql/data -d postgres
The result is an easy, persistent database!
Implicit creation cuts out the first step of volume creation. It occurs when a
docker service or
docker run command is fed the name of a volume that does not yet exist, and docker is forced to automatically create the named volume to continue. Note that this requires the
--volume-driver flag! Otherwise, a local (default) volume will be made.
docker run --name postgres \ -e POSTGRES_PASSWORD=mysecretpassword \ --volume-driver cio \ -v postgres-data:/var/lib/postgresql/data -d postgres
This results in the automatic creation of a default CIO volume. For
docker run commands, there is currently no way to customize the volume implicitly.
Data volumes can also be created implicitly with the
docker service create command. Unlike the
docker run command,
docker service create also allows storage to be provisioned with CIO’s volume options. This is accomplished through the
--mount flag, but with different syntax:
docker service create \ --mount source=mysqldb,target=/var/lib/mysql,volume-driver=cio,\ volume-opt=capacity=300,volume-opt=profile=MYSQL \ --replicas 1 \ -e MYSQL_ROOT_PASSWORD=mysecret \ --name mysql \ mysql
Source refers to the name of a (yet unprovisioned) docker volume, and target refers to the mount point within the container. It is worth noting that in the case of a conflict between argument and profile exists (here, the capacity), CIO will prioritize the argument provided.
As can be seen, the provisioning and usage of persistent storage is quick and easy!