docker网络问题导致dify添加API不能成功,如添加SearXNG
背景
dify添加SearXNG检索工具
使用dify添加SearXNG搜索工具,在工具栏输入
http://host.docker.internal:8081
不能添加成功
问题的核心是容器无法解析 host.docker.internal 这个域名,这通常是因为 Docker 的网络配置或宿主机的环境设置不支持该域名解析。
所以我选择在dify项目的docker配置文件中添加host配置
extra_hosts: # 添加 extra_hosts 配置
- "host.docker.internal:172.17.0.1" # 替换为宿主机的 IP 地址
具体如下
# API service
api:
image: langgenius/dify-api:0.15.3
restart: always
environment:
# Use the shared environment variables.
<<: *shared-api-worker-env
# Startup mode, 'api' starts the API server.
MODE: api
SENTRY_DSN: ${API_SENTRY_DSN:-}
SENTRY_TRACES_SAMPLE_RATE: ${API_SENTRY_TRACES_SAMPLE_RATE:-1.0}
SENTRY_PROFILES_SAMPLE_RATE: ${API_SENTRY_PROFILES_SAMPLE_RATE:-1.0}
depends_on:
- db
- redis
volumes:
# Mount the storage directory to the container, for storing user files.
- ./volumes/app/storage:/app/api/storage
networks:
- ssrf_proxy_network
- default
extra_hosts: # 添加 extra_hosts 配置
- "host.docker.internal:172.17.0.1" # 替换为宿主机的 IP 地址
# worker service
# The Celery worker for processing the queue.
worker:
image: langgenius/dify-api:0.15.3
restart: always
environment:
# Use the shared environment variables.
<<: *shared-api-worker-env
# Startup mode, 'worker' starts the Celery worker for processing the queue.
MODE: worker
SENTRY_DSN: ${API_SENTRY_DSN:-}
SENTRY_TRACES_SAMPLE_RATE: ${API_SENTRY_TRACES_SAMPLE_RATE:-1.0}
SENTRY_PROFILES_SAMPLE_RATE: ${API_SENTRY_PROFILES_SAMPLE_RATE:-1.0}
depends_on:
- db
- redis
volumes:
# Mount the storage directory to the container, for storing user files.
- ./volumes/app/storage:/app/api/storage
networks:
- ssrf_proxy_network
- default
extra_hosts: # 添加 extra_hosts 配置
- "host.docker.internal:172.17.0.1" # 替换为宿主机的 IP 地址
重新添加即可