docker compose backend container not found

I have two docker containers, one with a fastAPI back-end, one with a streamlit app as front-end. This is my docker compose yaml:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>version: '3.9'
services:
semcity-frontend:
image: semcity-frontend
environment:
- SEMCITY_BACKEND_URL=http://semcity-backend:8003/
ports:
- 8004:8004
networks:
local:
depends_on:
- semcity-backend
semcity-backend:
image: semcity-backend
environment:
- OPENAI_API_KEY=<api-key-here...>
ports:
- 8003:8003
networks:
local:
networks:
local:
external: true
</code>
<code>version: '3.9' services: semcity-frontend: image: semcity-frontend environment: - SEMCITY_BACKEND_URL=http://semcity-backend:8003/ ports: - 8004:8004 networks: local: depends_on: - semcity-backend semcity-backend: image: semcity-backend environment: - OPENAI_API_KEY=<api-key-here...> ports: - 8003:8003 networks: local: networks: local: external: true </code>
version: '3.9'

services:
  semcity-frontend:
    image: semcity-frontend
    environment:
      - SEMCITY_BACKEND_URL=http://semcity-backend:8003/
    ports:
      - 8004:8004
    networks:
      local:
    depends_on:
      - semcity-backend

  semcity-backend:
    image: semcity-backend
    environment:
      - OPENAI_API_KEY=<api-key-here...>
    ports:
      - 8003:8003
    networks:
      local:

networks:
  local:
    external: true

When I run this (docker-compose -f compose.yaml up), it spins up the two containers. But upon sending a request from the streamlit GUI in my browser, I get:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>semcity-semcity-frontend-1 | requests.exceptions.ConnectionError: HTTPConnectionPool(host='semcity-backend', port=8003): Max retries exceeded with url: /qa?question=asd&celex_ids=32015L2366&max_len=300 (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7f9cb4183950>: Failed to establish a new connection: [Errno 111] Connection refused'))
</code>
<code>semcity-semcity-frontend-1 | requests.exceptions.ConnectionError: HTTPConnectionPool(host='semcity-backend', port=8003): Max retries exceeded with url: /qa?question=asd&celex_ids=32015L2366&max_len=300 (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7f9cb4183950>: Failed to establish a new connection: [Errno 111] Connection refused')) </code>
semcity-semcity-frontend-1  | requests.exceptions.ConnectionError: HTTPConnectionPool(host='semcity-backend', port=8003): Max retries exceeded with url: /qa?question=asd&celex_ids=32015L2366&max_len=300 (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x7f9cb4183950>: Failed to establish a new connection: [Errno 111] Connection refused'))

My fastAPI app has a /qa endpoint like so:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>@app.post("/qa")
def submit(question: str, celex_ids: str, max_len: int):
relevant_celex_ids = celex_ids.split('_')
paragraphs, scores, celex_ids, article_ids, paragraph_ids = engine.rank_by_relatedness(question, relevant_celex_ids, 10)
context = create_context(zip(celex_ids, paragraphs, paragraph_ids, article_ids))
answer = answer_question(context, question)
return answer
</code>
<code>@app.post("/qa") def submit(question: str, celex_ids: str, max_len: int): relevant_celex_ids = celex_ids.split('_') paragraphs, scores, celex_ids, article_ids, paragraph_ids = engine.rank_by_relatedness(question, relevant_celex_ids, 10) context = create_context(zip(celex_ids, paragraphs, paragraph_ids, article_ids)) answer = answer_question(context, question) return answer </code>
@app.post("/qa")
def submit(question: str, celex_ids: str, max_len: int):
    relevant_celex_ids = celex_ids.split('_')
    paragraphs, scores, celex_ids, article_ids, paragraph_ids = engine.rank_by_relatedness(question, relevant_celex_ids, 10)
    context = create_context(zip(celex_ids, paragraphs, paragraph_ids, article_ids))
    answer = answer_question(context, question)
    return answer

In my streamlit code, I’m getting the URL from a sys env variable, like so:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>BACKEND_URL = os.environ.get('SEMCITY_BACKEND_URL')
url = ('%sqa?question=%s&celex_ids=%s&max_len=%i' %
(BACKEND_URL, question, '_'.join(celex_ids), max_words))
if st.button('Ask!'):
res = requests.post(url)
</code>
<code>BACKEND_URL = os.environ.get('SEMCITY_BACKEND_URL') url = ('%sqa?question=%s&celex_ids=%s&max_len=%i' % (BACKEND_URL, question, '_'.join(celex_ids), max_words)) if st.button('Ask!'): res = requests.post(url) </code>
BACKEND_URL = os.environ.get('SEMCITY_BACKEND_URL')
url = ('%sqa?question=%s&celex_ids=%s&max_len=%i' %
           (BACKEND_URL, question, '_'.join(celex_ids), max_words))

if st.button('Ask!'):
    res = requests.post(url)

This seems to do something, since the error message tells me that it tried at (host='semcity-backend', port=8003) (it’s apparently getting that much from my docker compose file). It doesn’t seem to get all the way there though. From what I’ve understood (definitely not an expert at docker though), if both containers share a “networks” (i.e., “local” in my case), they should be able to refer to each other by the service name. I’m not sure if this is ultimately a docker problem, but running my (python) code locally without docker, it all works, so I’m a bit lost. Any thoughts or ideas on what could be the problem would be greatly appreciated!

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật