Quantcast
Channel: Active questions tagged python - Stack Overflow
Viewing all articles
Browse latest Browse all 17419

Django-based Docker project will connect to local postgres DB on windows machines but not on a Mac or Linux machine

$
0
0

Been struggling with this issue for close to a month now and I am at my wits end.

I have the following docker-compose.yml file:

version: '3.8'services:  web:    container_name: targeting    build: ./Targeting    command: python manage.py runserver 0.0.0.0:80    volumes:      - ./:/usr/src/project/    ports:      - "80:80"  db:    env_file:      - ./.env    restart: always    image: postgres    container_name: postgres    environment:      - POSTGRES_DB=${NAME}      - POSTGRES_USER=${USER}      - POSTGRES_PASSWORD=${PASSWORD}      - POSTGRES_PORT=${PORT}    ports:      - "5432:5432"    volumes:      - postgres_data:/var/lib/postgresql/data/  pgadmin:    image: dpage/pgadmin4    container_name: pgadmin4_container    restart: always    ports:      - "8888:80"    environment:      PGADMIN_DEFAULT_EMAIL: user-name@domain-name.com      PGADMIN_DEFAULT_PASSWORD: strong-password    volumes:      - pgadmin-data:/var/lib/pgadminvolumes:  postgres_data:  pgadmin-data:

and I have the following .env file:

SECRET_KEY=random_secret_keyDEBUG=TRUENAME=postgresUSER=postgresPASSWORD=passwordHOST=dbPORT=5432

The following Dockerfile is used to create the python container:

# pull official base imageFROM python:3.11.4-slim-buster# set work directoryWORKDIR /usr/src/project# set environment variablesENV PYTHONDONTWRITEBYTECODE 1ENV PYTHONUNBUFFERED 1# install dependenciesRUN pip install --upgrade pipCOPY ../requirements.txt .RUN pip install -r requirements.txt# copy projectCOPY .. .

On a Windows machine, after a docker compose build and a docker compose up command is issued, the project will be up and running and the django project will connect to the postgres database perfectly fine. I have verified this on two Windows machines. However, on mac or linux, I get a "connection failed: FATAL: password authentication failed for the user "postgres" error and I have no idea why.

my settings.py file for Django looks like this. I use Python decouple to use .env variables.

from decouple import configDATABASES = {"default": {"ENGINE": "django.db.backends.postgresql","NAME": config('NAME'),"USER": config('USER'),"PASSWORD": config('PASSWORD'),"HOST": config('HOST'),"PORT": config('PORT')    }}

Anyone have any suggestions? I am guessing it could be something to do with paths, but I have not been able to find out the solution. Thanks.

I have tried credentials for a postgres database on a RDS instance in the env file and that worked fine on the Mac and linux machines.


Viewing all articles
Browse latest Browse all 17419

Latest Images

Trending Articles



Latest Images

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