The executable
uvicorn
could not be found.
58facettes
PROOP

10 months ago

Getting error "The executable uvicorn could not be found." when container tries to start the whole day!

Last version of Dockerfile:

FROM python:3.13-slim

WORKDIR /app

# Set UV_LINK_MODE to 'copy' as cache mounts are on a different filesystem
ENV UV_LINK_MODE=copy

# Install git, openssh-client, and PostgreSQL development libraries
RUN apt-get update && apt-get install -y --no-install-recommends \
    git \
    openssh-client \
    build-essential \
    libpq-dev \
    postgresql-client \
    && rm -rf /var/lib/apt/lists/*

# Install uv
COPY --from=ghcr.io/astral-sh/uv:latest /uv /usr/local/bin/uv
# Accept SSH private key as build argument
ARG SSH_PRIVATE_KEY

# Set up SSH for private repository access
RUN if [ -n "$SSH_PRIVATE_KEY" ]; then \
    mkdir -p ~/.ssh && \
    echo "$SSH_PRIVATE_KEY" > ~/.ssh/id_rsa && \
    chmod 600 ~/.ssh/id_rsa && \
    ssh-keyscan github.com >> ~/.ssh/known_hosts && \
    git config --global url."ssh://git@github.com/".insteadOf "https://github.com/"; \
    fi

# Copy dependency files
COPY pyproject.toml uv.lock ./

# Install dependencies
RUN --mount=type=cache,id=s/72b18e17-65d2-4255-9573-9ce8c11cf24c-/root/.cache/uv,target=/root/.cache/uv \
    uv sync --frozen --no-dev
# Clean up SSH key after installation (optional, for security)
RUN if [ -n "$SSH_PRIVATE_KEY" ]; then \
    rm -f ~/.ssh/id_rsa; \
    fi

# Copy application code
COPY app/ ./app/

# Expose port
EXPOSE 8000

# Run the application using uv run (which uses the virtual environment)
#CMD ["uv", "run", "uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "8000", "--log-level", "info"]
CMD [".venv/bin/python", "-m", "uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "8000", "--log-level", "info"]

It runs locally without a problem, but not at Railway

Logs: https://railway.com/project/e2ee0018-fea9-49e4-a014-3c2a8fe61491/service/72b18e17-65d2-4255-9573-9ce8c11cf24c?environmentId=f2cda1da-2248-4808-bf0e-1245e632803f&id=7769928e-a4f3-4ef3-94fa-880385d218c0#build

Solved

2 Replies

Railway
BOT

10 months ago

Hey there! We've found the following might help you get unblocked faster:

If you find the answer from one of these, please let us know by solving the thread!


58facettes
PROOP

10 months ago

Fixed with:

```

FROM python:3.13-slim WORKDIR /app # Set UV_LINK_MODE to 'copy' as cache mounts are on a different filesystem ENV UV_LINK_MODE=copy # Install git, openssh-client, and PostgreSQL development libraries RUN apt-get update && apt-get install -y --no-install-recommends \ git \ openssh-client \ build-essential \ libpq-dev \ postgresql-client \ && rm -rf /var/lib/apt/lists/* # Install uv COPY --from=ghcr.io/astral-sh/uv:latest /uv /usr/local/bin/uv # Accept SSH private key as build argument ARG SSH_PRIVATE_KEY # Set up SSH for private repository access RUN if [ -n "$SSH_PRIVATE_KEY" ]; then \ mkdir -p ~/.ssh && \ echo "$SSH_PRIVATE_KEY" > ~/.ssh/id_rsa && \ chmod 600 ~/.ssh/id_rsa && \ ssh-keyscan github.com >> ~/.ssh/known_hosts && \ git config --global url."ssh://git@github.com/".insteadOf "https://github.com/"; \ fi # Copy dependency files COPY pyproject.toml uv.lock ./ # Create virtual environment and install dependencies RUN --mount=type=cache,id=s/72b18e17-65d2-4255-9573-9ce8c11cf24c-/root/.cache/uv,target=/root/.cache/uv \ uv venv .venv && \ uv sync --frozen --no-dev # Clean up SSH key after installation (optional, for security) RUN if [ -n "$SSH_PRIVATE_KEY" ]; then \ rm -f ~/.ssh/id_rsa; \ fi # Copy application code COPY app/ ./app/ # Expose port EXPOSE 8000 # Add venv to PATH and run the application ENV PATH="/app/.venv/bin:$PATH" CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "8000", "--log-level", "info"]

```


Status changed to Solved 58facettes • 10 months ago


Welcome!

Sign in to your Railway account to join the conversation.

Loading...