Docker Build Failing with nixpacks – Python + Node/npx

77amirTRIAL

2 months ago

Hi

I'm deploying my FastAPI backend on Railway using nixpacks, and I’ve been troubleshooting this for hours with no luck. My project requires both Python (for FastAPI) and Node (for MCP tools), so I added a custom nixpacks.toml to explicitly include these providers. Here’s my current configuration:

--------------------------------------------------

providers = ["...", "python", "node"]

[phases.setup]

nixPkgs = ["...", "python313", "nodejs-18_x"]

[python]

version = "3.13"

--------------------------------------------------

Unfortunately, during the build stage, I encounter this error:

--------------------------------------------------

✕ [stage-0 4/18] RUN nix-env -if .nixpacks/nixpkgs-5624e1334b26ddc18da37e132b6fa8e93b481468.nix && nix-collect-garbage -d

process "/bin/bash -ol pipefail -c nix-env -if .nixpacks/nixpkgs-5624e1334b26ddc18da37e132b6fa8e93b481468.nix && nix-collect-garbage -d" did not complete successfully: exit code: 100

--------------------------------------------------

I believe the error might be related to how the providers and nix packages are being configured or parsed, but I haven't been able to pinpoint the issue. My goal is to ensure that the Docker build installs both the correct Python and Node environments so that my application (which leverages a no-code drag and drop editor for multi-agent workflows) runs smoothly.

Has anyone encountered a similar issue or have any suggestions on how to resolve this Docker build failure using nixpacks on Railway?

If not nixpacks, what should i use?

Thanks in advance!

ps my railway.toml file is

[build]

builder = "nixpacks"

buildCommand = "pip install -r requirements.txt"

[deploy]

startCommand = "PYTHONPATH=$PYTHONPATH:. python init_database.py && PYTHONPATH=$PYTHONPATH:. uvicorn main:app --host 0.0.0.0 --port $PORT"

healthcheckPath = "/"

healthcheckTimeout = 30

restartPolicyType = "on_failure"

[deploy.env]

OAUTHLIB_RELAX_TOKEN_SCOPE = "1"

Solved

11 Replies

2 months ago

Looks like you forgot \ after ENV PYTHONPATH=/app


Status changed to Awaiting User Response railway[bot] 2 months ago


77amirTRIAL

2 months ago

Hi thank you for replying. I really appreciate it. Could you clarify what you mean? This is my dockerfile

 Dockerfile for building and running the no-code drag and drop editor application

# Use Python 3.13 slim image as base
FROM python:3.13-slim

# Install system dependencies including Node.js and build essentials
RUN apt-get update && apt-get install -y --no-install-recommends \
    build-essential \
    curl \
    nodejs \
    npm \
    && rm -rf /var/lib/apt/lists/* \
    && apt-get clean

# Set working directory
WORKDIR /app

# Copy requirements first to leverage Docker cache
COPY requirements.txt .

# Install Python dependencies
RUN pip install --no-cache-dir -r requirements.txt


# Copy the rest of the application
COPY . .

# Set environment variables
# PYTHONPATH is set for module resolution, PORT for application server, and other settings for application configuration
ENV PYTHONPATH=/app \
ENV PORT=8000 
ENV PYTHONUNBUFFERED=1 
ENV OAUTHLIB_RELAX_TOKEN_SCOPE=1

# Initialize the database
RUN python init_database.py

# Expose the port the app runs on
EXPOSE 8000

# Start the application using uvicorn
CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8000"] 

Im 3 months into programming, please forgive me. Thank you


Status changed to Awaiting Railway Response railway[bot] 2 months ago


2 months ago

Now you've changed the syntax so now you need to remove the trailing \ slash after ENV PYTHONPATH=/app


Status changed to Awaiting User Response railway[bot] 2 months ago


brody

Now you've changed the syntax so now you need to remove the trailing \ slash after ENV PYTHONPATH=/app

77amirTRIAL

2 months ago

Hi Brody, Thank you again. I tried it and i got this error. Any idea what it could be?

Build time: 143.95 seconds

Feb 22 00:01:00

Feb 22 00:01:00

=========================

Feb 22 00:01:00

Container failed to start

Feb 22 00:01:00

=========================

Feb 22 00:01:00

Feb 22 00:01:00

The executable pythonpath=$pythonpath:. could not be found.


Status changed to Awaiting Railway Response railway[bot] 2 months ago


brody

Now you've changed the syntax so now you need to remove the trailing \ slash after ENV PYTHONPATH=/app

77amirTRIAL

2 months ago

This is where im at right now:

# Dockerfile for building and running the no-code drag and drop editor application

# Use Python 3.13 slim image as base
FROM python:3.13-slim

# Install system dependencies including Node.js and build essentials
RUN apt-get update && apt-get install -y --no-install-recommends \
    build-essential \
    curl \
    nodejs \
    npm \
    && rm -rf /var/lib/apt/lists/* \
    && apt-get clean

# Set working directory
WORKDIR /app

COPY __init__.py .

# Copy requirements first to leverage Docker cache
COPY requirements.txt .

# Install Python dependencies
RUN pip install --no-cache-dir -r requirements.txt

# Copy the rest of the application
COPY . /app

# Set environment variables separately to avoid any formatting issues
ENV PORT=8000
ENV OAUTHLIB_RELAX_TOKEN_SCOPE=1

# Initialize the database
RUN python init_database.py

# Expose the port the app runs on
EXPOSE 8000

# Start the application using uvicorn
CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8000"] 

The error im getting is The executable pythonpath=$pythonpath:. could not be found.


2 months ago

Can you try removing the start command in your railway.toml file?


Status changed to Awaiting User Response railway[bot] 2 months ago


77amirTRIAL

2 months ago

Ill do that right now


Status changed to Awaiting Railway Response railway[bot] 2 months ago


brody

Can you try removing the start command in your railway.toml file?

77amirTRIAL

2 months ago

I got a new error! but it got to the health check this time.

im not sure what it is

Error: Invalid value for '--port': '$PORT' is not a valid integer.

Feb 22 00:56:27

Usage: uvicorn [OPTIONS] APP

Feb 22 00:56:27

Try 'uvicorn --help' for help.

Feb 22 00:56:27

Feb 22 00:56:27

Error: Invalid value for '--port': '$PORT' is not a valid integer.


2 months ago

Switch your CMD line away from the exec format -

CMD uvicorn main:app --host 0.0.0.0 --port $PORT

Status changed to Awaiting User Response railway[bot] 2 months ago


77amirTRIAL

2 months ago

brody , its done it works, thank you man. I could not have done it without you. Thank you so much for being patient


Status changed to Awaiting Railway Response railway[bot] 2 months ago


2 months ago

Happy to help!


Status changed to Awaiting User Response railway[bot] 2 months ago


Status changed to Solved brody 2 months ago