after just a few minutes after I created my new space,my space was paused and 503 when restart.,
my code file:
| FROM Package hajimi · GitHub |
|---|
| EXPOSE 7860 |
| CMD [“uvicorn”, “app.main:app”, “–host”, “0.0.0.0”, “–port”, “7860”] |
after just a few minutes after I created my new space,my space was paused and 503 when restart.,
my code file:
| FROM Package hajimi · GitHub |
|---|
| EXPOSE 7860 |
| CMD [“uvicorn”, “app.main:app”, “–host”, “0.0.0.0”, “–port”, “7860”] |
That information alone isn’t enough to pinpoint the problem…
A Hugging Face Space shows 503 on restart when the platform cannot get your container into a healthy “listening web server” state. In practice that means one of these happened:
HF’s own Docker Spaces docs assume your app serves HTTP on a single exposed port (default 7860, configurable via app_port). (Hugging Face)
And forum guidance matches the symptom: “Paused + 503 on restart” usually means the restart failed because the container did not start correctly. (Hugging Face Forums)
cpu-basic). (Hugging Face)Your “a few minutes after creation” pattern is much more consistent with “container dies quickly” than with inactivity sleep. (Hugging Face)
–host and –port (en dash), not --host and --port (two ASCII hyphens)That character difference matters. Uvicorn’s CLI options are --host and --port. (uvicorn.dev)
If you pass –host, uvicorn treats it as an unknown argument and exits. When the process exits, the container stops. HF then serves 503.
Fix it:
FROM ghcr.io/googolplex35/hajimi:latest
EXPOSE 7860
CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "7860"]
Uvicorn also documents the required import-string format "<module>:<attribute>" (your app.main:app). (uvicorn.dev)
uvicorn is not installed in that base imageIf the image does not contain uvicorn, Docker will fail with “executable file not found” and exit immediately. That produces the same 503 symptom.
How to confirm: open Runtime logs on the Space page and look at the last lines.
app.main:app does not exist inside the containerYour Dockerfile does not COPY your repo code into the image. So app/main.py must already be inside ghcr.io/googolplex35/hajimi:latest. If it is not, you will get ModuleNotFoundError: No module named 'app' and the container exits.
Again, runtime logs will show this clearly.
HF routes traffic to the single exposed port (default 7860 unless you set app_port). (Hugging Face)
If your app binds to 127.0.0.1 or a different port, HF cannot reach it and you see 503.
Uvicorn expects --host 0.0.0.0 for “listen on all interfaces.” (uvicorn.dev)
Many Docker Spaces examples create a UID 1000 user and run as that user to avoid permission problems. (Docker)
If your base image assumes root-only paths (writing under /root, installing at runtime, etc.), it can crash or misbehave.
There are recent forum reports where Docker Spaces get stuck “Paused” and any restart yields 503 even with correct code. A common workaround is duplicating/recreating the Space or toggling settings to force a reschedule. (Hugging Face Forums)
Some users report 503 tied to prohibited libraries or policy enforcement. If logs hint at blocking or the Space never runs even with a minimal app, this is a possibility. (Hugging Face Forums)
If your FastAPI code is in the Space repo and not baked into the base image, use a Dockerfile that installs deps and copies code (this mirrors common Spaces guidance): (Docker)
FROM python:3.11-slim
RUN useradd -m -u 1000 user
USER user
ENV HOME=/home/user \
PATH=/home/user/.local/bin:$PATH
WORKDIR $HOME/app
COPY --chown=user requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt
COPY --chown=user . .
CMD ["sh", "-c", "uvicorn app.main:app --host 0.0.0.0 --port ${PORT:-7860}"]
Notes:
app_port in README.md YAML if you need a different port. (Hugging Face)${PORT:-7860} pattern is just a convenience. Hardcoding 7860 is also fine if your Space uses app_port: 7860.Go to your Space page. Click the status badge. Open Logs.
If the error is in the build, look at Build logs. If it crashes at runtime, look at Runtime logs.
Look specifically for:
ModuleNotFoundError (wrong import path or code not in image)Reproduce locally with the same image and command:
docker run -p 7860:7860 ..., and see the exact stderr traceback.app_port): (Hugging Face)--host and --port: (uvicorn.dev)–host/–port must be --host/--port. (uvicorn.dev)uvicorn, missing app.main:app, wrong port, or permission issues. (Hugging Face)