CLI Reference
The Railway Command Line Interface (CLI) lets you interact with your Railway project from the command line.
This document describes the commands available in the CLI.
For information on how to install the CLI and more examples of usage, see the CLI guide.
Add
Add a service to your project
~ railway add --help Add a service to your project Usage: railway add [OPTIONS] Options: -d, --database <DATABASE> The name of the database to add [possible values: postgres, mysql, redis, mongo] -s, --service [<SERVICE>] The name of the service to create (leave blank for randomly generated) -r, --repo <REPO> The repo to link to the service -i, --image <IMAGE> The docker image to link to the service -v, --variables <VARIABLES> The "{key}={value}" environment variable pair to set the service variables. Example: railway add --service --variables "MY_SPECIAL_ENV_VAR=1" --variables "BACKEND_PORT=3000" --json Output in JSON format -h, --help Print help (see a summary with '-h') -V, --version Print versionCompletion
Generate a shell-completions for the following shells: bash, elvish, fish, and powershell
~ railway completion --help Generate completion script Usage: railway completion [OPTIONS] <SHELL> Arguments: <SHELL> [possible values: bash, elvish, fish, powershell, zsh] Options: --json Output in JSON format -h, --help Print help -V, --version Print versionConnect
Connect to a database's shell (psql for Postgres, mongosh for MongoDB, etc.)
~ railway connect --help Connect to a database's shell (psql for Postgres, mongosh for MongoDB, etc.) Usage: railway connect [OPTIONS] [SERVICE_NAME] Arguments: [SERVICE_NAME] The name of the database to connect to Options: -e, --environment <ENVIRONMENT> Environment to pull variables from (defaults to linked environment) --json Output in JSON format -h, --help Print help -V, --version Print versionThis requires you to have the database's appropriate shell/client installed in your $PATH:
- Postgres:
psql(https://www.postgresql.org/docs/current/app-psql.html) - Redis:
redis-cli(https://redis.io/docs/ui/cli/) - MongoDB:
mongosh(https://www.mongodb.com/docs/mongodb-shell/) - MySQL:
mysql(https://dev.mysql.com/doc/refman/8.0/en/mysql.html)
Deploy
Deploy a template into your project
railway deploy --help Provisions a template into your project Usage: railway deploy [OPTIONS] Options: -t, --template <TEMPLATE> The code of the template to deploy -v, --variable <VARIABLE> The "{key}={value}" environment variable pair to set the template variables To specify the variable for a single service prefix it with "{service}." Example: bash railway deploy -t postgres -v "MY_SPECIAL_ENV_VAR=1" -v "Backend.Port=3000" --json Output in JSON format -h, --help Print help (see a summary with '-h') -V, --version Print versionDomain
Create a domain for a service
~ railway domain --help Add a custom domain or generate a railway provided domain for a service Usage: railway domain [OPTIONS] [DOMAIN] Arguments: [DOMAIN] Optionally, specify a custom domain to use. If not specified, a domain will be generated Options: -p, --port <PORT> The port to connect to the domain -s, --service <SERVICE> The name of the service to generate the domain for --json Output in JSON format -h, --help Print help (see more with '--help') -V, --version Print versionDocs
Open the Railway documentation site in the default browser
~ railway docs --help Open Railway Documentation in default browser Usage: railway docs [OPTIONS] Options: --json Output in JSON format -h, --help Print help -V, --version Print version```Down
Remove the most recent deployment
~ railway down --help Remove the most recent deployment Usage: railway down [OPTIONS] Options: -y, --yes Skip confirmation dialog --json Output in JSON format -h, --help Print help -V, --version Print versionEnvironment
Create, delete or link an environment
~ railway [env]ironment --help Create, delete or link an environment Usage: railway environment [OPTIONS] [ENVIRONMENT] [COMMAND] Commands: new Create a new environment delete Delete an environment [aliases: remove, rm] help Print this message or the help of the given subcommand(s) Arguments: [ENVIRONMENT] The environment to link to Options: --json Output in JSON format -h, --help Print help -V, --version Print versionView environment docs for more information.
If you run railway environment without specifying a name, you will be prompted with an environment selector that lists all your environments for the project.
railway environment new
Create a new environment
~ railway [env]ironment new --help Create a new environment Usage: railway environment new [OPTIONS] [NAME] Arguments: [NAME] The name of the environment to create Options: -d, --duplicate <DUPLICATE> The name of the environment to duplicate [aliases: copy] [short aliases: c] -v, --service-variable <SERVICE> <VARIABLE> Variables to assign in the new environment Note: This will only work if the environment is being duplicated, and that the service specified is present in the original environment Examples: railway environment new foo --duplicate bar --service-variable <service name/service uuid> BACKEND_PORT=3000 --json Output in JSON format -h, --help Print help (see a summary with '-h') -V, --version Print versionrailway environment delete
Delete an environment
~ railway [env]ironment delete --help Delete an environment Usage: railway environment delete [OPTIONS] [ENVIRONMENT] Arguments: [ENVIRONMENT] The environment to delete Options: -y, --yes Skip confirmation dialog --json Output in JSON format -h, --help Print help -V, --version Print versionNote: railway environment delete will not work if an account has 2FA and the terminal is not being run interactively.
Init
Create a new Project from the CLI
~ railway init --help Create a new project Usage: railway init [OPTIONS] Options: -n, --name <NAME> Project name -w, --workspace <NAME|ID> Workspace to create the project in --json Output in JSON format -h, --help Print help -V, --version Print versionLink
Connect to an existing Railway project
~ railway link --help Associate existing project with current directory, may specify projectId as an argument Usage: railway link [OPTIONS] Options: -e, --environment <ENVIRONMENT> Environment to link to -p, --project <PROJECT> Project to link to -s, --service <SERVICE> The service to link to -t, --team <TEAM> The team to link to. Use "personal" for your personal account --json Output in JSON format -h, --help Print help -V, --version Print versionRunning link with no project ID will prompt you to select a team and project.
List
List all projects in your Railway account
~ railway list --help List all projects in your Railway account Usage: railway list [OPTIONS] Options: --json Output in JSON format -h, --help Print help -V, --version Print versionLogin
Login to your Railway account
~ railway login --help Login to your Railway account Usage: railway login [OPTIONS] Options: -b, --browserless Browserless login --json Output in JSON format -h, --help Print help -V, --version Print versionThis will open the browser to https://railway.com/cli-login.
Browserless
If you are in an environment where the terminal cannot open a web browser, (i.e. SSH session or Codespaces), you can perform a browserless login.
~ railway login --browserless Browserless Login Please visit: https://railway.com/cli-login?d=SGVsbG8sIGtpbmQgc3RyYW5nZXIhIFRoYW5rcyBmb3IgcmVhZGluZyB0aGUgZG9jdW1lbnRhdGlvbiEgSSBob3BlIHlvdSdyZSBoYXZpbmcgYSB3b25kZXJmdWwgZGF5IDopCg== Your pairing code is: friendly-malicious-electric-soup Logged in as Nebula ([email protected])This will prompt you to go to a URL (you can copy and paste) and present you with a 4 word code that you need to verify. If the codes match, click "Verify" and you will be logged in.
Logout
Logout of your Railway account
~ railway logout --help Logout of your Railway account Usage: railway logout [OPTIONS] Options: --json Output in JSON format -h, --help Print help -V, --version Print versionLogs
View logs for the most recent deployment
~ railway logs --help View the most-recent deploy's logs Usage: railway logs [OPTIONS] Options: -d, --deployment Show deployment logs -b, --build Show build logs --json Output in JSON format -h, --help Print help -V, --version Print versionOpen
Open your current Railway project in the browser
~ railway open --help Open your project dashboard Usage: railway open [OPTIONS] Options: --json Output in JSON format -h, --help Print help -V, --version Print versionRun
Run a command using the Railway environment
~ railway run --help Run a local command using variables from the active environment Usage: railway run [OPTIONS] [ARGS]... Arguments: [ARGS]... Args to pass to the command Options: -s, --service <SERVICE> Service to pull variables from (defaults to linked service) -e, --environment <ENVIRONMENT> Environment to pull variables from (defaults to linked environment) --json Output in JSON format -h, --help Print help -V, --version Print versionThis also injects all environment variables associated with the databases you have installed in your project.
Service
Link a service to the current project
~ railway service --help Link a service to the current project Usage: railway service [OPTIONS] [SERVICE] Arguments: [SERVICE] The service to link Options: --json Output in JSON format -h, --help Print help -V, --version Print versionShell
Create a subshell (based on $SHELL) with all the variables from your project/environment/service loaded and accessible
~ railway shell --help Open a subshell with Railway variables available Usage: railway shell [OPTIONS] Options: -s, --service <SERVICE> Service to pull variables from (defaults to linked service) --json Output in JSON format -h, --help Print help -V, --version Print versionSSH
SSH into a project/service
~ railway ssh --help Connect to a service via SSH Usage: railway ssh [OPTIONS] [COMMAND]... Arguments: [COMMAND]... Command to execute instead of starting an interactive shell Options: -p, --project <PROJECT> Project to connect to (defaults to linked project) -s, --service <SERVICE> Service to connect to (defaults to linked service) -e, --environment <ENVIRONMENT> Environment to connect to (defaults to linked environment) -d, --deployment-instance <deployment-instance-id> Deployment instance ID to connect to (defaults to first active instance) --json Output in JSON format -h, --help Print help -V, --version Print versionStatus
View the status of your Railway project and user
~ railway status --help Show information about the current project Usage: railway status [OPTIONS] Options: --json Output in JSON format -h, --help Print help -V, --version Print versionUnlink
Disconnects the current directory from Railway
~ Disassociate project from current directory Usage: railway unlink [OPTIONS] Options: -s, --service Unlink a service --json Output in JSON format -h, --help Print help -V, --version Print versionYou will need to rerun railway link to use railway in this directory again.
Up
Deploy a directory to your Railway project
~ railway up --help Upload and deploy project from the current directory Usage: railway up [OPTIONS] [PATH] Arguments: [PATH] Options: -d, --detach Don't attach to the log stream -c, --ci Only stream build logs and exit after it's done -s, --service <SERVICE> Service to deploy to (defaults to linked service) -e, --environment <ENVIRONMENT> Environment to deploy to (defaults to linked environment) --no-gitignore Don't ignore paths from .gitignore --verbose Verbose output --json Output in JSON format -h, --help Print help -V, --version Print versionIf no path is provided, the top linked directory is deployed. The currently selected environment is used.
Variables
View a table of all the environment variables associated with your project and environment
~ railway variables --help Show variables for active environment Usage: railway variables [OPTIONS] Options: -s, --service <SERVICE> The service to show/set variables for -e, --environment <ENVIRONMENT> The environment to show/set variables for -k, --kv Show variables in KV format --set <SET> The "{key}={value}" environment variable pair to set the service variables. Example: railway variables --set "MY_SPECIAL_ENV_VAR=1" --set "BACKEND_PORT=3000" --json Output in JSON format -h, --help Print help (see a summary with '-h') -V, --version Print versionWhoami
View what user is currently authenticated with Railway
~ railway whoami --help Get the current logged in user Usage: railway whoami [OPTIONS] Options: --json Output in JSON format -h, --help Print help -V, --version Print versionVolume
Manage project volumes with options to list, add, delete, update, attach, and detach volumes
~ railway volume --help Manage project volumes Usage: railway volume [OPTIONS] <COMMAND> Commands: list List volumes add Add a new volume delete Delete a volume update Update a volume detach Detach a volume from a service attach Attach a volume to a service help Print this message or the help of the given subcommand(s) Options: -s, --service <SERVICE> Service ID -e, --environment <ENVIRONMENT> Environment ID --json Output in JSON format -h, --help Print help -V, --version Print versionRedeploy
Redeploy the currently deployed version of a service
~ railway redeploy --help Redeploy the latest deployment of a service Usage: railway redeploy [OPTIONS] Options: -s, --service <SERVICE> The service ID/name to redeploy from -y, --yes Skip confirmation dialog --json Output in JSON format -h, --help Print help -V, --version Print versionHelp
Help command reference
~ railway help Interact with Railway via CLI Usage: railway [OPTIONS] <COMMAND> Commands: add Add a service to your project completion Generate completion script connect Connect to a database's shell (psql for Postgres, mongosh for MongoDB, etc.) deploy Provisions a template into your project domain Generates a domain for a service if there is not a railway provided domain docs Open Railway Documentation in default browser down Remove the most recent deployment environment Change the active environment init Create a new project link Associate existing project with current directory, may specify projectId as an argument list List all projects in your Railway account login Login to your Railway account logout Logout of your Railway account logs View a deploy's logs open Open your project dashboard run Run a local command using variables from the active environment service Link a service to the current project shell Open a local subshell with Railway variables available status Show information about the current project unlink Disassociate project from current directory up Upload and deploy project from the current directory variables Show variables for active environment whoami Get the current logged in user volume Manage project volumes redeploy Redeploy the latest deployment of a service help Print this message or the help of the given subcommand(s) Options: --json Output in JSON format -h, --help Print help -V, --version Print versionEdit this file on GitHub