proxy_pool docker容器启动出错

wyyhbhjk  于 5个月前  发布在  Docker
关注(0)|答案(3)|浏览(104)

启动命令:

docker run --env db_type=REDIS --env db_host=127.0.0.1 --env db_port=6379 --env db_password=pwd_str -p 50014:5010 jhao104/proxy_pool

错误:

2020-04-04 21:41:40,653 ProxyManager.py[line:66] ERROR Error 111 connecting to 127.0.0.1:6379. Connection refused.
2020-04-04 21:41:40,653 ProxyManager.py[line:46] INFO ProxyFetch - freeProxy14: start
2020-04-04 21:41:40,740 ProxyManager.py[line:61] INFO ProxyFetch - freeProxy14: 36.248.133.5:9999    success
2020-04-04 21:41:40,741 ProxyManager.py[line:65] ERROR ProxyFetch - freeProxy14: error
2020-04-04 21:41:40,742 ProxyManager.py[line:66] ERROR Error 111 connecting to 127.0.0.1:6379. Connection refused.
2020-04-04 21:41:40,742 ProxyScheduler.py[line:35] INFO finish fetch proxy
Traceback (most recent call last):
  File "/usr/local/lib/python3.6/site-packages/redis/connection.py", line 552, in connect
    sock = self._connect()
  File "/usr/local/lib/python3.6/site-packages/redis/connection.py", line 609, in _connect
    raise err
  File "/usr/local/lib/python3.6/site-packages/redis/connection.py", line 597, in _connect
    sock.connect(socket_address)
ConnectionRefusedError: [Errno 111] Connection refused

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "proxyPool.py", line 52, in <module>
    cli()
  File "/usr/local/lib/python3.6/site-packages/click/core.py", line 764, in __call__
    return self.main(*args, **kwargs)
  File "/usr/local/lib/python3.6/site-packages/click/core.py", line 717, in main
    rv = self.invoke(ctx)
  File "/usr/local/lib/python3.6/site-packages/click/core.py", line 1137, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/usr/local/lib/python3.6/site-packages/click/core.py", line 956, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/usr/local/lib/python3.6/site-packages/click/core.py", line 555, in invoke
    return callback(*args, **kwargs)
  File "proxyPool.py", line 38, in schedule
    runScheduler()
  File "../Schedule/ProxyScheduler.py", line 48, in runScheduler
    rawProxyScheduler()
  File "../Schedule/ProxyScheduler.py", line 40, in rawProxyScheduler
    doRawProxyCheck()
  File "../Schedule/RawProxyCheck.py", line 65, in doRawProxyCheck
    for _proxy in pm.db.getAll():
  File "../DB/DbClient.py", line 102, in getAll
    return self.client.getAll()
  File "/usr/src/app/DB/RedisClient.py", line 107, in getAll
    item_dict = self.__conn.hgetall(self.name)
  File "/usr/local/lib/python3.6/site-packages/redis/client.py", line 2979, in hgetall
    return self.execute_command('HGETALL', name)
  File "/usr/local/lib/python3.6/site-packages/redis/client.py", line 875, in execute_command
    conn = self.connection or pool.get_connection(command_name, **options)
  File "/usr/local/lib/python3.6/site-packages/redis/connection.py", line 1347, in get_connection
    connection.connect()
  File "/usr/local/lib/python3.6/site-packages/redis/connection.py", line 557, in connect
    raise ConnectionError(self._error_message(e))
redis.exceptions.ConnectionError: Error 111 connecting to 127.0.0.1:6379. Connection refused.
slmsl1lt

slmsl1lt1#

如果要在容器内连宿主机上的服务,宿主机的127.0.0.1并不是容器内的127.0.0.1。
要实现这种有两种方式,

一是使用host网络模式

docker run --network host --env db_type=REDIS --env db_host=127.0.0.1 --env db_port=6379  -p 5010:5010 jhao104/proxy_pool

二是使用 host.docker.internal

docker run  --env db_type=REDIS --env db_host=host.docker.internal --env db_port=6379  -p 5010:5010 jhao104/proxy_pool

参考 https://segmentfault.com/q/1010000010440290

l2osamch

l2osamch2#

我也是一样的错误,群辉Docker

0s7z1bwu

0s7z1bwu3#

docker run --net=host --env DB_CONN=redis://:@host.docker.internal:6379/0 -p 5010:5010 jhao104/proxy_pool:latest

相关问题