How to Deploy Dockerized MCP Servers to Railway
You have built a powerful MCP server (likely for SAP, Oracle, or another legacy system), and it runs perfectly in Docker on your machine. Now you need it running 24/7 so your Agents can access it from anywhere.
We recommend Railway for this. Unlike other cloud providers, Railway has excellent support for raw Dockerfiles and handles the complex networking automatically.
🛑 Prerequisite: Make your Code “Cloud Aware”
Section titled “🛑 Prerequisite: Make your Code “Cloud Aware””Before you deploy, you must ensure your Python script listens on the port Railway assigns to it. Railway injects a PORT environment variable (e.g., 5678) that you cannot predict.
1. Update server.py
Section titled “1. Update server.py”Change your server startup logic to look like this:
if __name__ == "__main__": import os
# 1. Get the PORT from Railway (Default to 8000 for local testing) port = int(os.environ.get("PORT", 8000))
# 2. Bind to 0.0.0.0 (CRITICAL: 'localhost' will not work in the cloud) mcp.run(transport='sse', host='0.0.0.0', port=port)2. Update Dockerfile
Section titled “2. Update Dockerfile”Ensure you expose the default port so Railway’s health checks pass.
EXPOSE 80003. Clean Up Your Upload (.dockerignore)
Section titled “3. Clean Up Your Upload (.dockerignore)”Since we are using the CLI to upload your files (see below), we must prevent “heavy” local folders from being sent to the cloud.
Create a .dockerignore file in your root folder:
.git.envvenv/node_modules/__pycache__/*.pyc.DS_Store🚀 Deployment Strategy: The “Copyright Safe” Method
Section titled “🚀 Deployment Strategy: The “Copyright Safe” Method”If you are deploying an SAP or Oracle integration, you likely have a folder named nwrfcsdk or instantclient in your project.
⚠️ DANGER: You cannot commit these folders to a public GitHub repository. They are proprietary, licensed binaries.
Instead of using GitHub, we will use the Railway CLI. This uploads your local folder (including the SDK) directly to Railway’s secure build server without ever exposing it on public source control.
Step 1: Install the Railway CLI
Section titled “Step 1: Install the Railway CLI”Open your terminal and install the tool.
# macOS / Linuxnpm i -g @railway/cli
# Windows (via Scoop)scoop install railwayStep 2: Login and Link
Section titled “Step 2: Login and Link”Navigate to your project folder (where your Dockerfile is).
# Login to your accountrailway login
# Create a new project spacerailway init# > Select "Empty Project"# > Name it "sap-mcp-server"Step 3: Deploy
Section titled “Step 3: Deploy”This command zips up your current folder (respecting .dockerignore) and sends it to the cloud.
railway upYou will see a build log stream in your terminal. Railway is now building your Docker container using your local files (including the SAP SDK).
⚙️ Configuration (Environment Variables)
Section titled “⚙️ Configuration (Environment Variables)”Your code likely needs credentials (like SAP_USER, SAP_PASSWORD). Never hardcode these.
- Go to your Railway Dashboard.
- Click on your project card.
- Navigate to the Variables tab.
- Click Raw Editor and paste your
.envfile content:
SAP_ASHOST=192.168.1.50SAP_SYSNR=00SAP_CLIENT=100SAP_USER=MY_BOT_USERSAP_PASS=Secret123Note regarding VPNs: If your SAP system is on-premise, you cannot reach
192.168.x.xfrom the cloud directly. You must add the NordLayer or Tailscale service to your Railway project to bridge the network.
✅ Verification: Is it Alive?
Section titled “✅ Verification: Is it Alive?”Before connecting your agent, check the logs to ensure the server started correctly.
- Click on your service in the Railway canvas.
- Click the Deployments tab and select the active deployment.
- Click View Logs.
- You should see a message similar to:
INFO: Uvicorn running on http://0.0.0.0:PORT
If you see this, your “Bridge” is live!
🌐 Connecting Your Agent
Section titled “🌐 Connecting Your Agent”Once the deployment finishes (green checkmark), you need the public URL.
- Go to the Settings tab in Railway.
- Under Networking, click Generate Domain.
- You will get a URL like:
https://sap-mcp-server-production.up.railway.app.
Update your Agent code (CrewAI / LangGraph) to point to this new secure endpoint:
# In your local agent.pyremote_mcp = "[https://sap-mcp-server-production.up.railway.app/sse](https://sap-mcp-server-production.up.railway.app/sse)"
sap_agent = Agent( role="SAP Specialist", # ... mcps=[remote_mcp])🔧 Troubleshooting
Section titled “🔧 Troubleshooting”-
Error:
Standard_C_Plus_Plusorglibcnot found:- Cause: You are likely using an Alpine Linux image (
FROM python:alpine). - Fix: SAP requires standard libraries found in Debian. Always use
FROM python:3.10-slimorFROM python:3.10-bookworm.
- Cause: You are likely using an Alpine Linux image (
-
Build Failed (Missing Files):
- Cause: You might be deploying via GitHub instead of the CLI. GitHub ignores files listed in
.gitignore(usually including proprietary SDKs). - Fix: Ensure you use
railway upto upload the files directly from your disk.
- Cause: You might be deploying via GitHub instead of the CLI. GitHub ignores files listed in
-
App Crashing (Error R10):
- Cause: This usually means you didn’t bind to
0.0.0.0or didn’t use theos.environ.get("PORT")variable. Check the code snippet in Prerequisite #1.
- Cause: This usually means you didn’t bind to
🛡️ Quality Assurance
Section titled “🛡️ Quality Assurance”- Status: ✅ Verified
- Method: Docker / Railway CLI
- Auditor: AgentRetrofit CI/CD
Transparency: This page contains affiliate links.