1---
2title: Volumes
3description: Block disk in a Project. Mount it into a Service with MountVolume.
4---
5
6A [`Railway.Volume`](/providers/railway/volume) is block disk in a
7[Project](/railway/compute/projects). Create it disconnected (no
8`service`) and attach later with
9[`MountVolume`](/providers/railway/mountvolume), or pass `service` to
10attach at create time.
11
12The disk outlives deploys. `mountPath` updates in place. Changing
13`project`, `environment`, or `region` replaces the Volume.
14
15## Create a Volume
16
17Pass a Project and a mount path. Alchemy generates a unique name.
18The volume is disconnected until you attach a Service.
19
20```typescript
21const site = yield* Railway.Project("Site");
22const data = yield* Railway.Volume("Data", {
23 project: site,
24 mountPath: "/data",
25});
26```
27
28:::caution[Changing `project` replaces the Volume]
29The Volume is created in the new Project. The old Volume is deleted.
30:::
31
32## Mount into a Service
33
34Inside a [Service](/railway/compute/services)'s constructor, bind the Volume
35to a path and use it as a plain directory at runtime:
36
37```typescript
38export default class Api extends Railway.Service<Api>()(
39 "Api",
40 { project: Site, main: import.meta.url, port: 3000 },
41 Effect.gen(function* () {
42 const disk = yield* Railway.MountVolume(Data, { path: "/data" });
43 const fs = yield* FileSystem.FileSystem;
44
45 return {
46 fetch: Effect.gen(function* () {
47 const text = yield* fs.readFileString(`${disk.path}/hello.txt`);
48 // ...
49 }),
50 };
51 }).pipe(Effect.provide(Railway.MountVolumeLive)),
52) {}
53```
54
55At deploy time the binding writes `{ path, volumeId }` into the
56Service. Reconcile attaches the volume via `volumeInstanceUpdate`.
57At runtime you get `disk.path`.
58
59Railway allows one volume per Service. It does not give each replica
60its own disk. A second volume on the same Service is
61`Railway.MultipleVolumes`.
62
63## Attach at create time
64
65Pass `service` to attach when the Volume is created:
66
67```typescript
68const api = yield* Railway.Service("Api", {
69 project: site,
70 image: "hashicorp/http-echo",
71 port: 5678,
72});
73const data = yield* Railway.Volume("Data", {
74 project: site,
75 mountPath: "/data",
76 service: api,
77});
78```
79
80Updating `service` attaches or moves the volume in place. The
81target Service must not already have a volume.
82
83## Environment
84
85Defaults to the Project's primary environment. Pass a
86[Environment](/railway/compute/environments) (or `{ environmentId }`)
87to target another one.
88
89```typescript
90const staging = yield* Railway.Environment("Staging", { project: site });
91const data = yield* Railway.Volume("StagingData", {
92 project: site,
93 environment: staging,
94 mountPath: "/data",
95});
96```
97
98:::caution[Changing `environment` replaces the Volume]
99The Volume is created in the new environment. The old Volume is
100deleted.
101:::
102
103## Region
104
105Omit `region` to use Railway's default. Changing it replaces the
106Volume. See [Regions](/railway/compute/regions).
107
108```typescript
109const data = yield* Railway.Volume("Data", {
110 project: site,
111 mountPath: "/data",
112 region: "us-west2",
113});
114```
115
116## Backups
117
118[`Railway.VolumeBackup`](/providers/railway/volumebackup) is a
119snapshot of a volume instance. The volume should be attached to a
120Service — Railway only backups mounted volumes. `lock` drops the
121expiration. `schedules` (`DAILY` / `WEEKLY` / `MONTHLY`) is
122volume-instance state.
123
124```typescript
125const snap = yield* Railway.VolumeBackup("Nightly", {
126 volume: data,
127 lock: true,
128 schedules: ["DAILY", "WEEKLY"],
129});
130```
131
132Restore is destructive to the volume instance. Call
133`restoreVolumeBackup` — it is not a reconciler step. Volume backups
134are Pro-plan gated (`RailwayForbidden` on Hobby).
135
136## Where next
137
138- [Tutorial part 3](/railway/tutorial/part-3) — mount a disk into a
139 Service step by step.
140- [Services](/railway/compute/services) — `MountVolume`.
141- [`Volume` reference](/providers/railway/volume),
142 [`MountVolume` reference](/providers/railway/mountvolume), and
143 [`VolumeBackup` reference](/providers/railway/volumebackup).