0

I have postgres installed in my ubuntu18.04, and running on port 5432.

enter image description here

I have django application and its in docker.

my database connection in settings.py file is like below.

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.postgresql',
        'NAME': 'dbname',
        'USER': 'postgres',
        'PASSWORD': '',
        'HOST': '127.0.0.1',
        'PORT': 5432,
    }
}

when i run command sudo docker-compose run it gives me below error.

enter image description here

2
  • 1
    change your connection file for host details..give machine IP instead of 127.0.0.1 and make sure your machine IP with 5432 is accessible. Commented Jun 23, 2020 at 13:41
  • @BhagyashriMachale, its works, thank you very much Commented Jun 23, 2020 at 13:43

1 Answer 1

2

127.0.0.1 in your Django application refers to localhost in the Docker container, not your host machine.

Get the IP of your Ubuntu host, e.g. by running ifconfig, and configure your Django application to use that IP.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.