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

Some suggest to add CMD [“python”, “”, “runserver”, “”] in Dockerfile; didn’t work in this case. In django, ALLOWED_HOSTS = [‘’]

Console output (part of: see bold)

File “/usr/local/lib/python3.7/site-packages/django/db/backends/postgresql/”, line 178, in get_new_connection
connection = Database.connect(conn_params)
File “/usr/local/lib/python3.7/site-packages/psycopg2/”, 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” ( and accepting
TCP/IP connections on port 5432?

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

Source: StackOverflow