I am trying to deploy my django app on Ubuntu server. It is actually working on localhost with windows machine. Dockerfile
# pull official base image
FROM python:3.11.2-slim-buster
# set working directory
WORKDIR /usr/src/app
# set environment variables
ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1
# updated
# install system dependencies
RUN apt-get update \
&& apt-get -y install gcc postgresql \
&& apt-get clean
# install dependencies
RUN pip install --upgrade pip
COPY ./requirements.txt .
RUN pip install -r requirements.txt
# new
# copy entrypoint.sh
RUN apt-get update && apt-get install -y netcat
COPY ./entrypoint.sh /usr/src/app/entrypoint.sh
RUN chmod +x /usr/src/app/entrypoint.sh
# add app
COPY . .
# new
# run entrypoint.sh
ENTRYPOINT ["/usr/src/app/entrypoint.sh"]
docker-compose
version: '3.8'
services:
qutqaruv:
build: ./app
command: gunicorn qutqaruv_core.wsgi --bind 0.0.0.0:8001
volumes:
- ./app/:/usr/src/app/
- static_volume:/static
ports:
- "8001:8001"
env_file:
- ./app/.env.dev
depends_on:
- qutqaruv-db
nginx:
image: nginx:1.22.1
ports:
- "82:8081"
volumes:
- ./nginx/nginx-setup.conf:/etc/nginx/conf.d/default.conf:ro
- static_volume:/static
depends_on:
- qutqaruv
qutqaruv-db:
image: postgres:15
volumes:
- postgres_data:/var/lib/postgresql/data/
environment:
- POSTGRES_USER=qutqaruv
- POSTGRES_PASSWORD=qutqaruv
- POSTGRES_DB=qutqaruv_dev
volumes:
postgres_data:
static_volume:
entrypoint
#!/bin/sh
if [ "$DATABASE" = "postgres" ]
then
echo "Waiting for postgres..."
while ! nc -z $SQL_HOST $SQL_PORT; do
echo $SQL_HOST $SQL_PORT
sleep 0.1
echo "Got lost in this process"
done
echo "PostgreSQL started"
fi
python manage.py flush --no-input
python manage.py migrate
python manage.py collectstatic --no-input
exec "$@"
Django app can not find Postgres and running infinetly in while loop. Another application with similar configuration worked properly but now this application just showing "Got lost in the process" constantly. I followed testdriven tutorial.