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

时间:2019-11-23 18:04:52

标签: docker curl docker-compose celery urllib3

我的问题是当我在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

django容器的Docker文件:

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
'''

1 个答案:

答案 0 :(得分:0)

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

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