Deploy a Ktor App
Ktor is an asynchronous framework for creating connected applications in Kotlin, built by JetBrains.
Note: There is no official Railway template for Ktor yet. You can check the community for Ktor templates.
This guide covers how to deploy a Ktor app on Railway in three ways:
Deploy from a GitHub repo
To deploy a Ktor app on Railway directly from GitHub, follow the steps below:
- Create a New Project.
- Click Deploy from GitHub repo.
- Select your Ktor GitHub repo.
- Railway requires a valid GitHub account to be linked. If your Railway account isn't associated with one, you will be prompted to link it.
- Click Deploy Now.
Railway uses Railpack to detect and build Gradle projects automatically.
Note: Your Ktor app needs to bind to 0.0.0.0 and read the port from the PORT environment variable. You can do this in application.conf:
Or programmatically:
Once the deployment is successful, a Railway service will be created for you. By default, this service will not be publicly accessible.
To set up a publicly accessible URL for the service, navigate to the Networking section in the Settings tab of your new service and click on Generate Domain.
Deploy from the CLI
- Install and authenticate with the CLI.
cdinto your Ktor project directory.- You can skip this step if you are already in your app directory.
- Run
railway initwithin the app directory to create a new project. - Run
railway upto deploy.- The CLI will now scan, compress and upload your Ktor app files to Railway's backend for deployment.
Use a Dockerfile
-
Create a
Dockerfilein your Ktor app's root directory. -
Add the content below to the
Dockerfile: -
Either deploy via the CLI or from GitHub.
Railway automatically detects the Dockerfile, and uses it to build and deploy the app.
Note: Railway supports also deployment from public and private Docker images.
Next steps
Explore these resources to learn how you can maximize your experience with Railway: