uvicorncould not be found.
6 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
2 Replies
6 months ago
Hey there! We've found the following might help you get unblocked faster:
- 🧵 Subject: Issue Deploying FastAPI Backend on Railway with Docker
- 🧵 Issue Deploying FastAPI Backend on Railway with Docker
- 🧵 The executable 'cd' could not be found.
If you find the answer from one of these, please let us know by solving the thread!
6 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 • 6 months ago