R
Railway•10mo ago
rose

"Application Failed to Respond" error when using docker to build

My dockerfile works on my local machine but after deploying to Railway, it seems there might be something wrong with the port? I am still really new to production environments and am having trouble configuring my Dockerfile for a Django production environment that utilizes outside packages not compatible with Nixpacks. Here's what I have in my Dockerfile:
FROM python:3.11

# Set working directory
WORKDIR .

# Install dependencies
RUN apt-get update
RUN apt-get install -y texlive-full
RUN rm -rf /var/lib/apt/lists/*

COPY requirements.txt .

RUN pip install --no-cache-dir -r requirements.txt

COPY . .

EXPOSE 8000

CMD ["python", "manage.py", "runserver", "0.0.0.0:8000"]
FROM python:3.11

# Set working directory
WORKDIR .

# Install dependencies
RUN apt-get update
RUN apt-get install -y texlive-full
RUN rm -rf /var/lib/apt/lists/*

COPY requirements.txt .

RUN pip install --no-cache-dir -r requirements.txt

COPY . .

EXPOSE 8000

CMD ["python", "manage.py", "runserver", "0.0.0.0:8000"]
18 Replies
Percy
Percy•10mo ago
Project ID: c81346b6-183a-4331-af52-bc960a6108bf
rose
rose•10mo ago
c81346b6-183a-4331-af52-bc960a6108bf
Brody
Brody•10mo ago
use this dockerfile instead
FROM python:3.11

ENV PYTHONUNBUFFERED=1
ENV PIP_DISABLE_PIP_VERSION_CHECK=1

# Set working directory
WORKDIR /app

# Install dependencies
RUN apt-get update && \
apt-get install -y --no-install-recommends texlive-full && \
rm -rf /var/lib/apt/lists/*

COPY requirements.txt ./

RUN pip install --no-cache-dir -r requirements.txt

COPY . ./

CMD gunicorn mysite.wsgi
FROM python:3.11

ENV PYTHONUNBUFFERED=1
ENV PIP_DISABLE_PIP_VERSION_CHECK=1

# Set working directory
WORKDIR /app

# Install dependencies
RUN apt-get update && \
apt-get install -y --no-install-recommends texlive-full && \
rm -rf /var/lib/apt/lists/*

COPY requirements.txt ./

RUN pip install --no-cache-dir -r requirements.txt

COPY . ./

CMD gunicorn mysite.wsgi
replace mysite with the name of the folder that contains the wsgi.py file. make sure you have gunicorn in your requirements.txt file.
rose
rose•10mo ago
Tysm! what exactly does WORKDIR need to refer to? the folder that holds the Dockerfile? or the main app?
Brody
Brody•10mo ago
it sets the work directory within the image, has nothing to do with the project itself, but its where the project or project files will be copied into
rose
rose•10mo ago
ohh perfect thank you so much. building the updates now!
Brody
Brody•10mo ago
did you replace mysite?
rose
rose•10mo ago
yes I did thanks for your help! you're a god on here. will let you know if there's any problems! the app takes a while to build because of the huge volume of texlive-full 🥲
Brody
Brody•10mo ago
sounds good
rose
rose•10mo ago
I got the exact same error ahhh
rose
rose•10mo ago
Here's the build log:
Brody
Brody•10mo ago
do you have a start command set in the service settings?
rose
rose•10mo ago
hmmm no would that be in .wgsi file? actually so sorry I do have a start command in my railway.json file railway.json:
{
"$schema": "https://schema.up.railway.app/railway.schema.json",
"build": {
"builder": "DOCKERFILE"
},
"deploy": {
"startCommand": "python manage.py migrate && python manage.py collectstatic --noinput && gunicorn layoutGenerator.wsgi",
"restartPolicyType": "ON_FAILURE",
"restartPolicyMaxRetries": 10
}
}
{
"$schema": "https://schema.up.railway.app/railway.schema.json",
"build": {
"builder": "DOCKERFILE"
},
"deploy": {
"startCommand": "python manage.py migrate && python manage.py collectstatic --noinput && gunicorn layoutGenerator.wsgi",
"restartPolicyType": "ON_FAILURE",
"restartPolicyMaxRetries": 10
}
}
Brody
Brody•10mo ago
yeah that will overwrite the CMD directive in the Dockerfile
rose
rose•10mo ago
hmm okay should I take out the startCommand line in that? in the railway.json* ^ Okay thank you so much!! I took out that line and it is working now 🙂
Brody
Brody•10mo ago
i mean it wasnt working with that line either lol but now that im thinking about it, you do want the migrate and collectstatic stuff, so please restore your railway.json to what you sent me. then run the manage.py makemigrations command locally and try to redeploy
Want results from more Discord servers?
Add your server