我无法从 docker 容器连接到代理

I can't connect to the proxy from the docker container

我的问题是当我在 docker 容器内时无法连接到代理。

我可以从外部连接:

curl --proxy 127.0.0.1:24000 "http://lumtest.com/myip.json"

{"ip":"185.36.254.160","country":"PL","asn":{"asnum":62240,"org_name":"Clouvider Limited"},"geo":{"city":"Warsaw","region":"14","postal_code":"00-202","latitude":52.25,"longitude":21,"tz":"Europe/Warsaw"}}

但是当我尝试从 docker 容器内部连接时出现错误。

curl --proxy 127.0.0.1:24000 "http://lumtest.com/myip.json"
curl: (7) Failed to connect to 127.0.0.1 port 24000: Connection refused

我的 docker-compose 文件如下所示:

version: '3'

services:
  backend:
    build: ./
    volumes:
      - ./:/app
    env_file:
      - .env
    ports:
      - 8000:8888

  proxy:
    build:
      context: .
      dockerfile: luminati-lpm/Dockerfile
    ports:
      - 22999:22999
      - 22998:22998
      - 24000:24000

Docker django 容器文件:

FROM python:3.7.5

RUN mkdir /app
WORKDIR /app

# Add current directory code to working directory
ADD . /app/

# set default environment variables
ENV PYTHONUNBUFFERED 1
ENV LANG C.UTF-8
ENV DEBIAN_FRONTEND=noninteractive

ENV PORT=8888

RUN apt-get update && apt-get install -y --no-install-recommends \
        tzdata \
        python3-setuptools \
        python3-pip \
        python3-dev \
        python3-venv \
        git \
        postgresql-11 \
        && \
    apt-get clean && \
    rm -rf /var/lib/apt/lists/*

RUN pip3 install --upgrade pip
RUN pip3 install pipenv

RUN pipenv install --skip-lock --system --dev

EXPOSE 8888
EXPOSE 5432

CMD gunicorn estatefilter_backend.wsgi:application --bind 0.0.0.0:$PORT
'''

假设您在 backend 容器中,您应该将 127.0.0.1 更改为 proxy(容器名称):

curl --proxy proxy:24000 "http://lumtest.com/myip.json"