[Django]-127.0.0.1 refused to connect in docker django

4πŸ‘

βœ…

I was running my application using the command:

docker-compose run app python3 manage.py runserver 0.0.0.0:8000

With docker-compose you need to use the argument --service-ports to:

Run command with the service’s ports enabled and mapped to the host.

Thus my final command looked like this:

docker-compose run --service-ports app python3 manage.py runserver 0.0.0.0:8000

Documentation on run can be found here

πŸ‘€Preston

2πŸ‘

If you are running docker inside a virtual machine then you need to access your application through the virtual machine IP address and not using localhost or 127.0.0.1. Try to get the virtual machine IP. Also please specify in which platform/environment you installed and running the docker.

πŸ‘€Coder

Leave a comment