I am encountering an issue while deploying my application on Koyeb. The application fails to start and the logs show the following error:
vbnet
Copy code
Error: '$PORT' is not a valid port number.
Application exited with code 1. This usually indicates an application failure. Check that the command used to launch your application is correct.
What I’ve Done So Far:
- Checked the Environment Variables: I have confirmed that the
PORT
variable is set correctly in the Koyeb environment settings. It is defined as a valid number (5000
or8000
), depending on the configuration. - Reviewed Application Code:
- The application is designed to retrieve the
PORT
environment variable as shown below:
python
if __name__ == '__main__':
port = os.environ.get("PORT", "5000")
if not port.isdigit():
raise ValueError("The port value is not a valid number.")
app.run(host="0.0.0.0", port=int(port))
- The
Procfile
is configured as follows:
plaintext
web: gunicorn run:app --bind 0.0.0.0:$PORT
- Local Testing:
- I have tested this setup locally, and it works as expected without any issues when I manually set the
PORT
variable to5000
.
Issue:
Despite these configurations, the deployment process on Koyeb consistently fails with the error “$PORT
is not a valid port number.” I suspect there might be an issue with how the environment variable is being interpreted or passed within the Koyeb environment.
Could you please assist in diagnosing and resolving this issue? If there’s a specific configuration or a known issue that I might be missing, I would appreciate your guidance.
Additional Information:
- Application Framework: Flask
- Web Server: Gunicorn
- Deployment Method: GitHub push
Thank you for your help in resolving this issue promptly.