Learning paths / Containers / Persistent storage

On ComputeSphere: SphereFiles volumes mounted on a service

Reading · 5 min · Module 7, lesson 4 of 510 min left in this module

Module 7 · Persistent storageLesson 4 of 5

Goal: Describe how a SphereFiles volume attaches to ComputeSphere services at a path, and what changes when several spherelets share it.

Key idea

On ComputeSphere, the volume you used with docker run -v is a SphereFiles volume. It lives in an environment, you mount it on a service at a path such as /data, and your app sees an ordinary folder there.

The same idea, one level up

Locally, you created a volume and mounted it into a container. ComputeSphere runs your container as a spherelet, and a restart, or a redeploy that applies a change, replaces the spherelet the way docker rm and docker run replaced your container in the last lesson. So the rule is the same: files on the spherelet's own filesystem go with it, and files on a mounted volume stay.

There's no -v flag to type. You set it up in the console, in two places, on any plan:

  • A volume in the environment, under Storage management, in a fixed size such as Files 10 GB ($2.50 a month).
  • A mount on each service that needs it, from the volume's Mounts, with the Mount path your app writes to.

Lesson 5.5.2, SphereFiles volumes, walks through both.

What carries over from Docker

  • The mount path must match your app. If your app writes to /app/data and you mount /data, the files still land on the spherelet's own filesystem.
  • Mount a folder your app only writes to, never your code folder. On ComputeSphere, the volume hides whatever the image had at that path.
  • Two containers can share a volume, as in the last lesson, and two writers to the same file still need care.

What's different

A SphereFiles volume is shared. A service with a volume can run several spherelets, and every spherelet of every service that mounts it sees the same files. If two of them might write the same file at the same moment, use file locks in your app or give each one its own folder.

File ownership works differently from Docker. Files written as root are stored as user 1000; other users keep their own user ID. New files and folders take group 1000. Make sure the user your app runs as (lesson 3.4.3) can write the folder it uses.

Volumes are created and mounted in the console. csph can list them (csph volumes ls) and copy files to and from them (csph files cp), but it doesn't mount them, and computesphere.yaml doesn't declare them, so note a service's volume and mount path in your README.

A volume also isn't a backup. It keeps data through redeploys, not through a deleted volume or a bug that corrupts a file.

Check yourself

Your service mounts a SphereFiles volume at /data, and you scale it to 3 spherelets. What do the two new spherelets see at /data?

In the docs