Storage
Keep your files and the workspace's configuration when the container is recreated, by persisting two directories: /workspace and ~/.ws.
Persistent Storage
Any data created inside a container is lost when the container is removed or recreated, for example to upgrade the image. To keep it (or to share it between containers), mount a named volume on each directory:
docker run \
-v ws:/home/kloud/.ws \
-v workspace:/workspace \
ghcr.io/kloudkit/workspace:v0.6.0In the command above:
- The volume named
workspaceis mounted on/workspace, the workspace root. - The volume named
wsis mounted on~/.ws, where the workspace keeps its configuration. - You can use any volume names.
- Docker automatically creates each volume on first execution.
Alternatively, you can manually create a volume:
docker volume create workspaceTo list all existing volumes:
docker volume ls💡 TIP
For simplicity and consistency, use named volumes over bind mounts whenever possible.
Persisting ~/.ws
Several workspace features store their configuration under ~/.ws (/home/kloud/.ws), including sideloaded extensions, startup and session scripts, drop-in CA certificates, the seed source, and your shell and REPL history (~/.ws/history). Because this directory lives inside the container, its contents are lost when the container is recreated, unless you persist it separately as shown above.
When a container is first created, ~/.ws and its standard subdirectories (not their contents) are re-owned by kloud, even when the mounted volume starts out owned by root.
Kubernetes
With Kubernetes, create a single PersistentVolumeClaim for the entire workspace and mount sub-paths of it, which keeps volume management simple.
The following demonstrates this practice (the paths and names are for illustration only):
# Pod specs
volumeMounts:
- name: data
mountPath: /workspace
subPath: workspace
- name: data
mountPath: /home/kloud/.ws
subPath: ws
- name: data
mountPath: /home/kloud/.config/helm
subPath: helm
volumes:
- name: dataNamed Volumes vs. Bind Mounts
Named Volumes
- Managed by Docker and stored in a Docker-controlled location on the host.
- Abstracted from the host file system, offering ease of use and portability.
- The initial content of the container directory is copied to the volume automatically.
Bind Mounts
- Directly link a specific directory or file on the host system to the container.
- Provide greater control but require explicit paths and manual host management.
- Can cause conflicting file ownership and permissions.
- When using Windows based mounts, all files will have an insecure mode of
777. - When using Linux based mounts, there may be an ownership discrepancy.