2 months ago
Hello Railway Team!
I'm having a persistent issue deploying a monorepo project. My repository contains a C#/.NET backend and a React frontend, each with its own Dockerfile.
The problem is that Railway's Railpack builder is trying to run automatically and failing, because it doesn't know how to handle the project structure.
I've tried to solve this by adding a railway.json file to the root of my repository to explicitly define the Dockerfile build for each service. However, even after deleting and recreating the project multiple times, Railpack still runs and ignores my railway.json configuration.
Could you please help me understand why my railway.json file is being ignored?
GitHub Repo: https://github.com/rol-xm/mbconnect-billing-system
2 Replies
2 months ago
You'll want to deploy the backend and frontend each in their own service. You can do this by:
Creating 2 services
Adding the repo to both
For each service, specify the directory the service will deploy from (maybe in your case it'd be
/backendand/frontend)
There's a full guide for this here: https://docs.railway.com/tutorials/deploying-a-monorepo
NOTE: This is assuming this is an isolated monorepo with no shared directories or anything, lmk if this isn't the case
2 months ago
Hey rol-xm,
This is a very common point of confusion when deploying monorepos with railway.json, and it's a great question. Your approach of using this file is excellent for keeping your deployment configuration as code (Infrastructure as Code).
The moderator's suggestion of setting the root directory for each service in the UI is a valid workaround, but let's solve your actual question: "Why is my railway.json file being ignored?"
The Reason: The Project Creation Flow
The most likely reason your railway.json is being ignored is because of how the project is being created. If you simply connect a GitHub repository and let Railway auto-detect its contents, it will use its "Railpack" build system by default and completely bypass the railway.json file.
To use your configuration file, you must explicitly tell Railway to do so during the initial setup.
The Solution: Correctly Deploying from railway.json
Here are the exact steps to get it working. You will need to start with a fresh project.
Delete the existing, failing project from your Railway dashboard.
Click New Project and then select Deploy from GitHub repo.
Choose your
mbconnect-billing-systemrepository.This is the crucial step. After Railway analyzes your repo, it will present deployment options. Do not click the default "Deploy Now" button. Instead, look for and select the option that says "Deploy from railway.json file".
Railway will now read your
railway.jsonfile. Instead of creating one failing service, it will automatically provision and configure the two services ("backend" and "frontend") that you have defined.
Verify Your railway.json File
To be certain your configuration is correct, here is a properly formatted railway.json for a monorepo structure like the one in your repository. You can compare this against your own file.
JSON
{
"$schema": "https://railway.app/railway.schema.json",
"services": [
{
"name": "backend",
"build": {
"builder": "DOCKERFILE",
"dockerfilePath": "backend/Dockerfile",
"dockerContext": "backend"
}
},
{
"name": "frontend",
"build": {
"builder": "DOCKERFILE",
"dockerfilePath": "frontend/Dockerfile",
"dockerContext": "frontend"
}
}
]
}
Important Note: Notice the dockerContext property. This tells Docker to use the backend or frontend directory as its starting point for the build. This is essential for commands like COPY . . inside your Dockerfiles to work correctly.
Following these steps should solve the issue and get your monorepo deploying just as you intended.
Hope this helps!
Status changed to Solved dev • about 2 months ago

