Using Volumes

Volumes allow you to store persistent data for services on Railway.

Volume

Creating A Volume

You can create a new volume through the Command Palette (⌘K) or by right-clicking the project canvas to bring up a menu:

Creating a volume via command palette

via command palette

Creating a volume via context menu

via right-click menu

When creating a volume, you will be prompted to select a service to connect the volume to:

Connect volume to service

You must configure the mount path of the volume in your service:

Connect volume to service

Using the Volume

The volume mount point you specify will be available in your service as a directory to which you can read/write. If you mount a volume to /foobar, your application will be able to access it at the absolute path /foobar.

Relative Paths

Nixpacks, the default buildpack used by Railway, puts your application files in an /app folder at the root of the container. If your application writes to a directory at a relative path, and you need to persist that data on the volume, your mount path should include the app path.

For example, if your application writes data to ./data, you should mount the volume to /app/data.

Provided Variables

Attaching a Volume to a service will automatically make these environment variables available to the service at runtime:

  • RAILWAY_VOLUME_NAME: Name of the volume (e.g. foobar)
  • RAILWAY_VOLUME_MOUNT_PATH: Mount path of the volume (e.g. /foobar)

You do not need to define these variables on the service, they are automatically set by Railway at runtime.

Volume Availability

Volumes are mounted to your service's container when it is started, not during build time.

If you write data to a directory at build time, it will not persist on the volume, even if it writes to the directory to which you have mounted the volume.

Volumes are not mounted as overlays.

Permissions

Volumes are mounted as the root user. If you run an image that uses a non-root user, you should set the following variable on your service:

RAILWAY_RUN_UID=0

Edit this file on GitHub