我有兩個容器中,我怎麼能在Python文件與Django的Web服務器Docker-compose在python文件中包含服務名稱的訪問容器?
多克爾 - compose.yml文件訪問另一個容器
version: '2'
services:
web:
build: ./web/
command: python3 manage.py runserver 0.0.0.0:8001
volumes:
- ./web:/code
ports:
- "8001:80"
networks:
- dock_net
container_name: con_web
depends_on:
- "api"
links:
- api
api:
build: ./api/
command: python3 manage.py runserver 0.0.0.0:8000
volumes:
- ./api:/code
ports:
- "8000:80"
networks:
- dock_net
container_name: con_api
networks:
dock_net:
driver: bridge
Python的文件:
我可以從mail_string形式
mail = request.POST.get('mail_string', '')
url = 'http://con_api:8000/api/'+mail+'/?format=json'
resp = requests.get(url=url)
return HttpResponse(resp.text)
我請求API容器並獲得價值,但我不知道IP地址
是的,這很好!但是,如果它是狀態更新或問題,我會感到困惑嗎? – Ayushya