Skip to content
Dashboard

Start command and port

Copy page
View as Markdown

Grayspar starts each service with a command it works out from your code, and tells the service which port to listen on. Most apps need nothing from you. This page covers the cases that do.

A service with a Dockerfile starts with the Dockerfile’s CMD. A Dockerfile with no CMD fails its build with this message:

Terminal window
This image has no start command. Add a CMD line to the Dockerfile.

Any other service builds with Railpack, which picks the start command for the framework it recognises. For example, Railpack starts a Next.js app with next start, and a FastAPI app with uvicorn.

When Railpack can’t tell how to start your app, or starts it the wrong way, add a file called Procfile to the service’s folder. Its web line holds the command:

Procfile
web: uvicorn server:app --host 0.0.0.0 --port $PORT

A Streamlit app is a common case, because Railpack sees a Python project and can’t tell that app.py is a Streamlit app:

Procfile
web: streamlit run app.py --server.port $PORT --server.address 0.0.0.0

If nothing in a folder says how to start it, the deploy stops before building and names the folder:

Terminal window
Nothing in api says how to start it.

A service has to listen on the port in its PORT variable, on the address 0.0.0.0. Grayspar sets PORT to 8080, or to the port a Dockerfile’s EXPOSE line names. An app that listens on localhost alone can’t be reached.

If your app always listens on one port, set PORT to that port:

Terminal window
grayspar env set PORT=3000

A service with a path that doesn’t answer on its port fails to deploy, and the version already running stays live. The deployment’s log says what went wrong:

Terminal window
This service isn't answering on port 8080. If it uses another port, set PORT to that port. If it takes no requests, run grayspar service set worker --no-path and deploy again.

A background worker that takes no requests needs no port. Give it no path, as Services and paths describes.