Skip to content

Persisting Data

If your app needs to persist data between restarts or upgrades, it can do so by requesting access to a part of the Portal's file system. Use this feature for a database or user-data in the shape of files. Shared directories allow data exchange between apps.


App-specific directories

For each installed app, Portal creates a separate app-directory inside its file system and allows the app to mount subdirectories of that directory into itself by specifying them in the app.json. This feature is based on Docker bind mounts.

Initially, these directories will be empty and your app can arbitrarily read and write inside them. If your app is stopped, the mounted directories remain intact and will still be there when your app restarts. If you release a new version of your app, it is your job to detect whether the content of the mounted directories was created by the old version and migrate it if needed.

You might not want to run your application as root inside your container but as some other user. In this case, it would not have access to the mounted directories, since they are owned by root. In order to allow access, you can change the mounted directories' owner by defining its user and group id. Set it to the values of the user that runs the app.

Use these app-specific directories to persist data that is used only by your app.

Example

JSON
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
...
  "data_dirs": [
    "/user_data",
    {
      "path": "/more_data",
      "uid": 1000,
      "gid": 1000
    }
  ],
...

Shared directories

Portal defines a set of shared directories for which your app can request access to. They are mounted inside your app's file system at a path that is specified in the app.json. Use these directories to access preexisting user data and share data with other apps that have access.

Available shared directories are:

  • documents
  • media
  • music

Example

JSON
1
2
3
4
5
6
7
8
9
...
  "data_dirs": [
    "/user_data",
    {
      "path": "/documents",
      "shared_dir": "documents"
    }
  ],
...

Built-In Services

Each Portal runs some built-in services that your app may use. For example, your app can get its own database at the Portal's Postgres instance and use it to store its data. Take a look at the section about Portal's internal services for more information.