Spent 2+ hours trying to deploy: Error: '$PORT' is not a valid port number.
cbdoc
FREEOP
9 months ago
# Use an official Python runtime as a parent image
FROM python:3.11-slim
# Set the working directory in the container
WORKDIR /app
# Install system dependencies
RUN apt-get update && apt-get install -y \
gcc \
&& rm -rf /var/lib/apt/lists/*
# Copy the requirements file into the container at /app
COPY requirements.txt .
# Install any needed packages specified in requirements.txt
RUN pip install --no-cache-dir -r requirements.txt
# Copy the rest of the application's code into the container at /app
COPY . .
# Declare PORT as build argument so Railway can inject it
ARG PORT
ENV PORT=${PORT:-8080}
# Set environment variables
ENV FLASK_APP=run.py
ENV PYTHONUNBUFFERED=1
# Expose the port
EXPOSE $PORT
# Command to run the application
CMD exec gunicorn run:app --bind 0.0.0.0:$PORT --workers 1I have tried every possible combination or CMD exec known to man. I am so frustrated with this and ready to move on to another service.
1 Replies
9 months ago
Hello,
The PORT variable is not available at build time.
Simply remove lines 22, 23, and 30 from your Dockerfile and it should work as intended.
Best,
Brody
Status changed to Awaiting User Response Railway • 9 months ago
Railway
BOT
7 months ago
This thread has been marked as solved automatically due to a lack of recent activity. Please re-open this thread or create a new one if you require further assistance. Thank you!
Status changed to Solved Railway • 7 months ago