【问题标题】:I can't connect to the proxy from the docker container我无法从 docker 容器连接到代理
【发布时间】:2019-11-23 18:04:52
【问题描述】:

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

【问题讨论】:

    标签: docker curl docker-compose celery urllib3


    【解决方案1】:

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

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

    【讨论】:

      猜你喜欢
      • 2020-02-14
      • 1970-01-01
      • 2020-02-09
      • 1970-01-01
      • 2019-10-23
      • 1970-01-01
      • 2015-05-01
      • 1970-01-01
      • 2020-02-08
      相关资源
      最近更新 更多