Docker“错误:在分配给网络的默认值中找不到可用的、非重叠的 IPv4 地址池"

编程入门 行业动态 更新时间:2024-10-23 07:17:24
本文介绍了Docker“错误:在分配给网络的默认值中找不到可用的、非重叠的 IPv4 地址池"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个目录apkmirror-scraper-compose,其结构如下:

<预><代码>.├── docker-compose.yml├── 隐私│ ├── 配置│ └── Dockerfile├── 刮板│ ├── Dockerfile│ ├── newnym.py│ └── 需求.txt└── 托└── Dockerfile

我正在尝试运行以下 docker-compose.yml:

版本:'3'服务:隐私:构建:./privoxy端口:- 8118:8118"链接:- 托托:建造:上下文:./tor参数:密码: ""端口:- 9050:9050"- 9051:9051"刮刀:构建:./scraper链接:- 托- 隐私

torDockerfile 在哪里

来自 alpine:latest曝光 9050 9051ARG密码运行 apk --update 添加器运行回声ControlPort 9051">>/etc/tor/torrcRUN echo "HashedControlPassword $(tor --quiet --hash-password $password)" >>/etc/tor/torrcCMD ["tor"]

对于 privoxy 来说是

来自 alpine:latest暴露8118运行 apk --update 添加 privoxy复制配置/etc/privoxy/configCMD ["privoxy", "--no-daemon"]

其中 config 由两行组成

监听地址 0.0.0.0:8118forward-socks5/tor:9050 .

scraperDockerfile

FROM python:2.7-alpine添加 ./刮刀WORKDIR/刮刀运行 pip install -r requirements.txtCMD ["python", "newnym.py"]

其中 requirements.txt 包含单行 requests.最后,程序 newnym.py 旨在简单地测试使用 Tor 更改 IP 地址是否有效:

 from time 导入睡眠,时间作为请求导入请求导入 telnetlibdef get_ip():IPECHO_ENDPOINT = 'http://ipecho/plain'HTTP_PROXY = 'http://privoxy:8118'返回 req.get(IPECHO_ENDPOINT, proxies={'http': HTTP_PROXY}).textdef request_ip_change():tn = telnetlib.Telnet('tor', 9051)tn.read_until("转义字符是'^]'.", 2)tn.write('认证"
')tn.read_until("250 OK", 2)tn.write("信号NEWNYM
")tn.read_until("250 OK", 2)tn.write("退出
")tn.close()如果 __name__ == '__main__':dts = []尝试:而真:ip = get_ip()t0 = 时间()request_ip_change()而真:new_ip = get_ip()如果 new_ip == ip:睡觉(1)别的:休息dt = 时间() - t0dts.append(dt)print("{} -> {} in ~{}s".format(ip, new_ip, int(dt)))除了键盘中断:打印(停止...")打印(平均值:{}".格式(总和(dts)/len(dts)))

docker-compose build 构建成功,但如果我尝试 docker-compose up,我会收到以下错误消息:

使用默认驱动创建网络apkmirrorscrapercompose_default"错误:在要分配给网络的默认值中找不到可用的、非重叠的 IPv4 地址池

我尝试搜索有关此错误消息的帮助,但找不到任何帮助.导致此错误的原因是什么?

解决方案

遵循 Peter Hauge 的 href="https://stackoverflow/questions/43720339/docker-error-could-not-find-an-available-non-overlapping-ipv4-address-pool-am#comment74485284_43720339">评论,运行 docker network ls 后,我看到(除其他行外)以下内容:

网络 ID 名称驱动程序范围dc6a83d13f44 桥桥本地ea98225c7754 docker_gwbridge 桥本地107dcd8aa889 主机主机本地

带有 NAMEDRIVER 作为 host 的行似乎是他所指的网络已经在您的主机上创建".因此,按照 https://gist.github/bastman/5b57ddb3c11942094f8d01a97d

docker network rm $(docker network ls | grep "bridge" | awk '//{ print $1 }')

现在 docker-compose up 工作(尽管 newnym.py 产生错误).

I have a directory apkmirror-scraper-compose with the following structure:

.
├── docker-compose.yml
├── privoxy
│   ├── config
│   └── Dockerfile
├── scraper
│   ├── Dockerfile
│   ├── newnym.py
│   └── requirements.txt
└── tor
    └── Dockerfile

I'm trying to run the following docker-compose.yml:

version: '3'

services:
  privoxy:
    build: ./privoxy
    ports:
      - "8118:8118"
    links:
      - tor

  tor:
    build:
      context: ./tor
      args:
        password: ""
    ports:
      - "9050:9050"
      - "9051:9051"

  scraper:
    build: ./scraper
    links:
      - tor
      - privoxy

where the Dockerfile for tor is

FROM alpine:latest
EXPOSE 9050 9051
ARG password
RUN apk --update add tor
RUN echo "ControlPort 9051" >> /etc/tor/torrc
RUN echo "HashedControlPassword $(tor --quiet --hash-password $password)" >> /etc/tor/torrc
CMD ["tor"]

that for privoxy is

FROM alpine:latest
EXPOSE 8118
RUN apk --update add privoxy
COPY config /etc/privoxy/config
CMD ["privoxy", "--no-daemon"]

where config consists of the two lines

listen-address 0.0.0.0:8118
forward-socks5 / tor:9050 .

and the Dockerfile for scraper is

FROM python:2.7-alpine
ADD . /scraper
WORKDIR /scraper
RUN pip install -r requirements.txt
CMD ["python", "newnym.py"]

where requirements.txt contains the single line requests. Finally, the program newnym.py is designed to simply test whether changing the IP address using Tor is working:

from time import sleep, time

import requests as req
import telnetlib


def get_ip():
    IPECHO_ENDPOINT = 'http://ipecho/plain'
    HTTP_PROXY = 'http://privoxy:8118'
    return req.get(IPECHO_ENDPOINT, proxies={'http': HTTP_PROXY}).text


def request_ip_change():
    tn = telnetlib.Telnet('tor', 9051)
    tn.read_until("Escape character is '^]'.", 2)
    tn.write('AUTHENTICATE ""
')
    tn.read_until("250 OK", 2)
    tn.write("signal NEWNYM
")
    tn.read_until("250 OK", 2)
    tn.write("quit
")
    tn.close()


if __name__ == '__main__':
    dts = []
    try:
        while True:
            ip = get_ip()
            t0 = time()
            request_ip_change()
            while True:
                new_ip = get_ip()
                if new_ip == ip:
                    sleep(1)
                else:
                    break
            dt = time() - t0
            dts.append(dt)
            print("{} -> {} in ~{}s".format(ip, new_ip, int(dt)))
    except KeyboardInterrupt:
        print("Stopping...")
        print("Average: {}".format(sum(dts) / len(dts)))

The docker-compose build builds successfully, but if I try docker-compose up, I get the following error message:

Creating network "apkmirrorscrapercompose_default" with the default driver
ERROR: could not find an available, non-overlapping IPv4 address pool among the defaults to assign to the network

I tried searching for help on this error message, but couldn't find any. What is causing this error?

解决方案

Following Peter Hauge's comment, upon running docker network ls I saw (among other lines) the following:

NETWORK ID          NAME                                    DRIVER              SCOPE
dc6a83d13f44        bridge                                  bridge              local
ea98225c7754        docker_gwbridge                         bridge              local
107dcd8aa889        host                                    host                local

The line with NAME and DRIVER as both host seems to be what he is referring to with "networks already created on your host". So, following https://gist.github/bastman/5b57ddb3c11942094f8d0a97d461b430, I ran the command

docker network rm $(docker network ls | grep "bridge" | awk '/ / { print $1 }')

Now docker-compose up works (although newnym.py produces an error).

这篇关于Docker“错误:在分配给网络的默认值中找不到可用的、非重叠的 IPv4 地址池"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

更多推荐

[db:关键词]

本文发布于:2023-03-31 04:17:03,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/795995.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:中找   默认值   错误   地址   网络

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!