如何使用Docker容器作为代理?

时间:2020-04-26 22:41:18

标签: python docker mitmproxy

我有以下docker-compose:

version: '3'
services:
  mitmproxy:
    image: johnmccabe/mitmweb
    container_name: mitmproxy
    command: --cadir /ca --wiface 0.0.0.0 
    restart: always
    ports:
        #- "8080:8080"
        - "8081:8081"

  python:
    image: python
    build: ./python-socks-example
    command: python3 /home/project/socks-example.py
    volumes:
      - ./python-socks-example:/home/project/
    depends_on:
       - mitmproxy
    container_name: python
    restart: always

我希望我的python HTTP请求通过另一个容器上的mitmproxy。这是python代码:

import requests
import time

while(True):
    time.sleep(5)
    print("gonna connect")
    resp = requests.get('http://google.com', 
                    proxies=dict(http='socks5://user:pass@server.com:8080',
                                 https='socks5://user:pass@server.com:8080'))
    print(resp)
    print("done")
    time.sleep(2)

如何连接python的网络以通过mitmproxy容器?

0 个答案:

没有答案