Django server connection error with Docker Toolbox in OS X Yosemite

I run the following yml file with $docker-compose up command. I’m developing a REST API with django (Udemy “Build a Backend REST API with Python & Django – Advanced”).

system: OS X 10.10.5
Docker version 18.03.0-ce
docker-compose version 1.20.1

Q:I am unable to access localhost with 127.0.0.1

Some suggest to add CMD [“python”, “manage.py”, “runserver”, “0.0.0.0:8000”] in Dockerfile; didn’t work in this case. In django settings.py, ALLOWED_HOSTS = [‘192.168.99.100’]

Console output (part of: see bold)

File “/usr/local/lib/python3.7/site-packages/django/db/backends/postgresql/base.py”, line 178, in get_new_connection
connection = Database.connect(conn_params)
File “/usr/local/lib/python3.7/site-packages/psycopg2/__init__.py”, line 130, in connect
conn = _connect(dsn, connection_factory=connection_factory, **kwasync)
django.db.utils.OperationalError: **could not connect to server: Connection refused

Is the server running on host “db” (172.19.0.2) and accepting
TCP/IP connections on port 5432?

I’m super new to this stuff, appreciate your help and suggestions.

Source: StackOverflow