Hangar works the way Railway does: a project holds services built from a repository, databases run next to them on a private network, and you pay for what they use. Hangar builds with Railpack, the builder Railway created, so a repository that builds on Railway builds on Hangar without changes.
This page is written so an AI agent can follow it step by step through Hangar's MCP server. Every step names the tool the agent calls. You can follow it by hand in the dashboard too.
Railway keeps running during the whole move. Nothing changes for your users until you switch DNS in the last step.
With your AI agent#
- Connect Hangar to your agent. For Claude Code:
claude mcp add --transport http --scope user hangar https://mcp.tryhangar.io/mcp
-
Install the Railway CLI, sign in with
railway login, and runrailway linkin the repository so the agent can read the project. -
In the repository, ask:
Move this Railway project to Hangar following https://tryhangar.io/docs/migrate-from-railway.
Keep Railway running. Ask me before restoring data and before any DNS change.
The rest of this page is what the agent does.
1Take stock of the Railway project#
Before creating anything, list what has to move:
- Services. For each one: its repository, branch and root directory, or its Docker image.
railway statusnames the project and environment; the Railway dashboard lists the services. - Variables.
railway variables --service <name> --jsonprints a service's variables with their values. Note which ones are references, such as${{Postgres.DATABASE_URL}}or${{shared.API_KEY}}. - Config as code. A
railway.jsonorrailway.tomlin the repository holds build and deploy settings: builder, Dockerfile path, build command, start command, pre-deploy command, watch patterns and cron schedule. - Databases. Engine and size of each one.
- Volumes. Mount path and size of each one.
- Domains. Every custom domain on every service.
- Code that names Railway. Search the repository for
RAILWAY_andrailway.internal.
Show this inventory to the user before going on.
2Create the project#
Call create_project with the Railway project's name. It returns the environmentId of the production environment, where every service below goes. If the Railway project has a staging environment you want too, add it with create_environment.
Pick the region closest to the one Railway used: list_regions lists Hangar's regions. Put every service and database of the project in the same region.
3Create the databases#
For each Railway database, call create_database with the same engine (postgres, mysql, mongo or redis), a name and the region. Hangar generates the password.
4Copy the data#
Ask the user before this step: it reads production data from Railway.
- On Railway, take the database's public URL from its variables:
DATABASE_PUBLIC_URLfor PostgreSQL,MYSQL_PUBLIC_URLfor MySQL,MONGO_PUBLIC_URLfor MongoDB. - On Hangar, the user turns on Public networking for the new database (see Connect from outside). Then
get_database_connectionwithreveal: truereturns itspublicUrl. - Dump from Railway and restore into Hangar on the machine the agent runs on:
# PostgreSQL
pg_dump "$RAILWAY_URL" --format=custom --no-owner --no-acl --file=railway.dump
pg_restore --no-owner --no-acl --dbname="$HANGAR_URL" railway.dump
# MySQL: the clients take host, port, user and password from each URL as flags
mysqldump --single-transaction --routines --triggers \
-h <railway-host> -P <railway-port> -u <user> -p<password> <database> > railway.sql
mysql -h <hangar-host> -P <hangar-port> -u <user> -p<password> <database> < railway.sql
# MongoDB
mongodump --uri="$RAILWAY_URL" --archive=railway.archive
mongorestore --uri="$HANGAR_URL" --archive=railway.archive
Use client tools of the same major version as the database or newer. A Redis that only holds a cache or a queue usually needs no copy.
- Compare row counts of the main tables on both sides, then have the user turn public networking off again. Delete the dump file when you are done.
This copy is a rehearsal. You take a final one right before the DNS switch, in step 9.
5Create the services#
For each Railway service built from GitHub, call create_app_from_github with:
environmentIdfrom step 2;repositoryandbranch, the ones Railway deploys;rootDirectory, if Railway's root directory is not the repository root;builder: leave it out for Railpack, ordockerfile(withdockerfilefor a path other thanDockerfile) when Railway builds a Dockerfile;regionId, the same region as the databases.
If Hangar's GitHub App cannot see the repository, the answer has a link: give it to the user, then try again.
The first deployment starts right away and may fail without its variables. That is expected; the service is deployed again in step 7.
6Move the settings and variables#
Build and deploy settings. Map railway.json or railway.toml to configure_service:
| Railway | Hangar (configure_service) |
|---|---|
build.builder | builder, in lowercase (RAILPACK becomes railpack) |
build.dockerfilePath | dockerfile |
build.buildCommand | buildCommand |
build.watchPatterns | watchPaths |
deploy.startCommand | startCommand |
deploy.preDeployCommand | preDeployCommand |
deploy.cronSchedule | cronSchedule, then deploy once. See Cron jobs |
deploy.numReplicas | replicas |
The file can stay in the repository; Hangar ignores it.
Variables. Set them with set_env, one call per service:
- Plain values are copied as they are.
- Database references such as
${{Postgres.DATABASE_URL}}are not copied. Callconnect_databasewith the app, the database from step 3 and the variable name instead. It writes the internal URL, password included, without it passing through the conversation. - Shared variables (
${{shared.KEY}}) are copied as values into each service that uses them. To keep one copy, the user can create an environment variable in the dashboard and reference it as${{environment.KEY}}. See Environment variables. - Railway's own variables are left out. Hangar sets
PORT. If the code readsRAILWAY_PUBLIC_DOMAIN,RAILWAY_ENVIRONMENT_NAMEor anotherRAILWAY_variable, set a variable of your own with the Hangar value and update the code to read it. - Service-to-service calls over
<name>.railway.internalare pointed at the other service's URL, whichget_serviceshows.
What the agent cannot do through MCP, and the user does in the dashboard:
- Volumes. Create one with the same mount path in the service's Settings → Storage, and copy its files. See Volumes.
7Deploy and check#
For each service, call deploy_service, then wait_for_deployment. If a build fails, read get_deployment_logs, fix the cause and deploy again.
Once a service is live:
- open its generated URL, from
get_service, and check the main pages or endpoints; - read
get_service_logswithminLevel: "error"; - read
list_requestswitherrorsOnly: trueafter some traffic.
Ask the user to test the app on its generated address before going on.
8Add the domains#
For each custom domain, call add_domain with the service, the host and the port the app listens on. The answer gives the DNS record to create. Do not create it yet. Give the records to the user for step 9.
9Switch over#
This is the only step with a short pause in writes. The user decides when.
- Put the app on Railway in maintenance mode, or stop the workers that write, so the database stops changing.
- Take the final copy of each database, as in step 4, restoring over the rehearsal data. For PostgreSQL, add
--clean --if-existstopg_restore. - Deploy the Hangar services again, so they start against the final data.
- The user changes the DNS records at their DNS provider to the values from step 8. HTTPS turns on once they resolve.
- Watch
get_service_logsandlist_requestswhile traffic moves over.
Keep the Railway project for a few days, stopped, in case you need to look something up. Then delete it on Railway.
What carries over#
| Railway | Hangar |
|---|---|
| Project, environment, service | The same: project, environment and service |
| Railpack and Dockerfile builds | The same builders. See Builds |
| PostgreSQL, MySQL, MongoDB, Redis | The same engines, plus MariaDB and libSQL. See Databases |
| TCP proxy for a database | Public networking |
| Volumes | Volumes |
| Cron schedule | Cron jobs |
| PR environments | Preview deployments |
| Custom domains | Domains and HTTPS |
railway up from a local folder | prepare_upload through MCP. See AI agents (MCP) |
For pricing and the differences between the two platforms, see Hangar vs Railway.