#wsl #docker #proxy 容器内的 `127.0.0.1` 指向容器自身,无法访问宿主机代理。需用 Docker 内置 DNS 名称替代。 解决方案 将 `127.0.0.1` 替换为 `host.docker.internal`,Docker 会自动解析为宿主机 IP。 ``` FROM python:3.12-slim WORKDIR /app RUN apt-get update && apt-get install -y \ libpq-dev gcc \ && rm -rf /var/lib/apt/lists/* COPY requirements/base.txt requirements/base.txt RUN pip install --no-cache-dir \ --proxy http://host.docker.internal:10808 \ --timeout 120 \ -r requirements/base.txt COPY . . EXPOSE 8000 CMD ["uvicorn", "config.asgi:application", "--host", "0.0.0.0", "--port", "8000"] ``` 其他命令同理 apt `apt-get -o Acquire::http::Proxy="http://host.docker.internal:10808" update` curl `curl -x http://host.docker.internal:10808 ` 注意事项 - 代理软件(Clash 等)需开启「允许局域网连接」 - 端口号按实际代理端口调整,Clash 默认 `7890` - `host.docker.internal` 在 Docker Desktop(Windows/Mac)及 WSL2 环境下均可用 - 避免在 Dockerfile 中硬编码 `ENV HTTPS_PROXY=http://127.0.0.1:...`,容器内无法访问