I use docker-compose. I want to make request to localhost. But I'm getting this error:
requests.exceptions.ConnectionError:
HTTPConnectionPool(host='0.0.0.0', port=9011): Max retries exceeded
with url: /api/user/registration (Caused by
NewConnectionError('<urllib3.connection.HTTPConnection object at
0x7fac61209110>: Failed to establish a new connection: [Errno 111]
Connection refused'))
My code:
import requests
response = requests.get('http://127.0.0.1:9011')
print(response.content)
This is my docker-compose.yml.
version: '3.4'
services:
web:
build: .
command: runserver
env_file:
- .env
volumes:
- 'static:/opt/app/static:rw'
ports:
- 8000:8000
volumes:
static:
I have find the answer. You should add network_mode: host to docker-compose.yml
version: '3.4'
services:
web:
build: .
command: runserver
env_file:
- .env
volumes:
- 'static:/opt/app/static:rw'
ports:
- 8000:8000
network_mode: host # Added this
volumes:
static:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With