Quantcast
Channel: Active questions tagged ubuntu - Stack Overflow
Viewing all articles
Browse latest Browse all 6052

Cannot access Django project homepage (Docker)

$
0
0

I'm building an app with Django, but although my app runs fine (at least, it's what CLI tells me) I can´t access it via browser.

The docker-compose build and up works just fine, I get this output:

 matt $ docker-compose run app sh -c "python manage.py runserver"             [+] Creating 2/2✔ Network nexus_default  Created                                                                         0.0s ✔ Container nexus-db-1   Created                                                                         0.1s [+] Running 1/1✔ Container nexus-db-1  Started                                                                          0.2s Watching for file changes with StatReloaderPerforming system checks...System check identified no issues (0 silenced).March 08, 2024 - 23:21:49Django version 5.0.3, using settings 'app.settings'Starting development server at http://127.0.0.1:8000/Quit the server with CONTROL-C.

But I can't access it through my browser (Screenshot attached)browser-error

My configs are below

Dockerfile

FROM python:3.12-alpine3.19LABEL maintainer="Matheus Tenório"ENV PYTHONUNBUFFERED 1COPY ./requirements.txt /tmp/requirements.txtCOPY ./requirements.dev.txt /tmp/requirements.dev.txtCOPY ./app /appWORKDIR /appEXPOSE 8000ARG DEV=falseRUN python -m venv /py && \    /py/bin/pip install --upgrade pip && \    apk add --update --no-cache postgresql-client && \    apk add --update --no-cache --virtual .tmp-build-deps \        build-base postgresql-dev musl-dev && \    /py/bin/pip install -r /tmp/requirements.txt && \    if [ $DEV = "true" ]; \      then /py/bin/pip install -r /tmp/requirements.dev.txt ; \    fi && \    rm -rf /tmp && \    apk del .tmp-build-deps && \    adduser \        --disabled-password \        --no-create-home \    djangouser && \    chown djangouser:djangouser -R /app/ENV PATH="/py/bin:$PATH"USER djangouser

docker-compose.yml

version: "3.12"services:  app:    build:      context: .      args:        - DEV=true    ports:      - "8000:8000"    volumes:      - ./app:/app    command: >        sh -c "python manage.py wait_for_db &&               python manage.py migrate &&               python manage.py runserver 0.0.0.0:8000"    environment:      - DB_HOST=db      - DB_NAME=${DB_NAME}      - DB_USER=${DB_USER}      - DB_PASSWORD=${DB_PASSWORD}    depends_on:      - db  db:    image: postgres:16-alpine3.19    volumes:      - dev-db-data:/var/lib/postgresql/data    environment:      - POSTGRES_DB=${DB_NAME}      - POSTGRES_USER=${DB_USER}      - POSTGRES_PASSWORD=${DB_PASSWORD}volumes:  dev-db-data:

.env

DB_NAME="my_db"DB_USER="my_user"DB_PASSWORD="my_password"

settings.py (Here's just the configs I changed from default)

import osALLOWED_HOSTS = ["0.0.0.0","127.0.0.1","localhost",]# Database# https://docs.djangoproject.com/en/5.0/ref/settings/#databasesDATABASES = {'default': {'ENGINE': 'django.db.backends.postgresql','HOST': os.environ.get('DB_HOST'),'NAME': os.environ.get('DB_NAME'),'USER': os.environ.get('DB_USER'),'PASSWORD': os.environ.get('DB_PASSWORD'),    }}

Also, this is my docker psdocker-ps

TEST


Viewing all articles
Browse latest Browse all 6052

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>