Docker "ERROR: could not find an available, non-overlapping IPv4 address pool among the defaults to assign to the network"

185,415

Solution 1

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.com/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).

Solution 2

I've seen it suggested docker may be at its maximum of created networks. The command docker network prune can be used to remove all networks not used by at least one container.

My issue ended up being, as Robert commented about: an issue with openvpn service openvpn stop 'solved' the problem.

Solution 3

I ran into this problem because I had OpenVPN running. As soon as I killed OpenVPN, docker-compose up fired right up, and the error disappeared.

Solution 4

I ran in this problem with OpenVPN working as well and I've found a solution where you should NOT stop/start OpenVPN server.

Idea that You should specify what exactly subnet you want to use. In docker-compose.yml write:

networks:
  default:
    driver: bridge
    ipam:
      config:
        - subnet: 172.16.57.0/24

That's it. Now, default network will be used and if your VPN did not assign you something from 172.16.57.* subnet, you're fine.

Solution 5

I have the same problem. I ran docker system prune -a --volumes, docker network prune, but neither helped me.

I use a VPN, I turned off the VPN and, after it docker started normal and was able to create a network. After that, you can enable VPN again.

Share:
185,415

Related videos on Youtube

Kurt Peek
Author by

Kurt Peek

Hi, I'm Kurt Peek, a backend engineer at Apple.

Updated on February 18, 2022

Comments

  • Kurt Peek
    Kurt Peek over 1 year

    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.net/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 ""\r\n')
        tn.read_until("250 OK", 2)
        tn.write("signal NEWNYM\r\n")
        tn.read_until("250 OK", 2)
        tn.write("quit\r\n")
        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?

    • Robert
      Robert about 6 years
      Do you have a VPN connected? Also, have you tried restarting your compueter? (I am googling) github.com/moby/moby/issues/30295
    • Jinna Balu
      Jinna Balu almost 4 years
      docker network prune. This will resolve your issue
  • jb.
    jb. almost 6 years
    If you need to run docker alongside vpn here is possible solution: stackoverflow.com/q/45692255/7918.
  • berkes
    berkes over 5 years
    Same here with another VPN provider (expressvpn).
  • Nicolai
    Nicolai about 5 years
    The same problem with running OpenVPN
  • David Ficociello
    David Ficociello about 5 years
    So I had the same issue and I'm wondering why this is happening. Why does Docker networking get confused when connected to a VPN.
  • Liviu Ilea
    Liviu Ilea almost 5 years
    OpenVPN Service was the issue for me.
  • Sweet Chilly Philly
    Sweet Chilly Philly almost 5 years
    To add to the above answer, if you get any issue like this pruning the system can really help. Docker system prune can also be a fix, but please be careful, this can remove your DB, only use this if you don't care for you DB, or if your DB container is running then this command is safe as it only prunes things not being used by at least one container.
  • Attila Szeremi
    Attila Szeremi over 4 years
    I would never have guessed. Thanks so much!
  • Nicolas
    Nicolas over 4 years
    I had the same problem with Private Internet Access
  • XtraSimplicity
    XtraSimplicity over 4 years
    My VPN connection was on the same subnet as the one docker was trying to use. Disconnecting solved the problem for me. :)
  • Douglas Liu
    Douglas Liu over 4 years
    I've added routes rather than redirect-gateway def1 to get around the issue without killing my openvpn service.
  • iBug
    iBug almost 4 years
    This is great! My server box can't stand without OpenVPN so advices on (even temporarily) disabling VPN are all nonsense to me.
  • michnovka
    michnovka almost 4 years
    this should be the accepted answer, as simply killing VPN is stupid
  • Rodrigo Hernández Mota
    Rodrigo Hernández Mota over 3 years
    Same problem when using PIA VPN.
  • dstromberg
    dstromberg over 3 years
    Isn't 172.177.57.0/24 a routed newtork? If so, it could cause problems contacting a limited number of hosts on the internet.
  • Arenim
    Arenim over 3 years
    yep, a glitch here. Would be better to use one from 172.16.*.* subnet
  • Damien Roche
    Damien Roche over 3 years
    Imagine a life where our tools give us useful debugging information.
  • IMB
    IMB over 3 years
    I've no VPN running but docker-compose down fixed it for me
  • Sma Ma
    Sma Ma over 3 years
    same problem because because I had VPN called globalprotect from paloaltonetworks running. As soon as I disconnect VPN the error disappeared. After the docker network is created you can enable your VPN again.
  • lucidyan
    lucidyan over 3 years
    I don't think that using 172.177.57.* is a good idea, because it not in the en.wikipedia.org/wiki/Private_network#Private_IPv4_addresses‌​. Use addresses within this range.
  • tephyr
    tephyr over 3 years
    The specific command to switch from OpenVPN to the WireGuard protocol for NordVPN is nordvpn set technology NordLynx. It is not a separate product, and currently is only available on Linux & iOS.
  • Jaza
    Jaza about 3 years
    Thanks so much for this solution! I need to run docker-compose with NetScaler (nsgclient on Ubuntu) VPN enabled, because various scripts in our docker images make requests to servers within our corporate network. This does the trick for me.
  • chovy
    chovy about 3 years
    is this a question or an answer?
  • Stefan van den Akker
    Stefan van den Akker about 3 years
    More a: my adventures in Docker-network land and how I stumbled onto something that stuck.
  • Abhay Maniyar
    Abhay Maniyar about 3 years
    This worked. I tried docker network prune but it didn't help then I noticed this answer. Disconnecting with vpn worked immediately.
  • therobyouknow
    therobyouknow almost 3 years
    same problem with Speedify VPN v9.9.0.8564 on Ubuntu 20.04. I don't think I saw this issue on Ubuntu 18.04 whilst running Speedify though.
  • Tobias Ernst
    Tobias Ernst over 2 years
    Thanks a lot for the answer. Restarting the docker service is required after making the changes to /etc/docker/daemon.json.
  • Willian
    Willian over 2 years
    Thank you so much @Вячеслав Калякин! Turning Off VPN solved my case as well.
  • Benny64
    Benny64 over 2 years
    For anyone who still has the issue after stopping VPN and running docker network prune, you may have to restart your PC. That solved it for me!
  • Noman Ur Rehman
    Noman Ur Rehman about 2 years
    Perhaps add a bit more details to this answer as to what the problem is and how this command solves it. Otherwise, it seems to get lost in the scrollfest because it is very short :D
  • Steven Rosato
    Steven Rosato about 2 years
    Thank you for this! It worked perfectly and no additional installs were required for me, just running nordvpn set technology NordLynx did the trick.
  • dexter2305
    dexter2305 about 2 years
    This should be marked as the answer instead of ``` docker network prune ``` or re-configuring the default bridge in the compose which are not scalable. In this case, pool can always be added.
  • Stephane
    Stephane almost 2 years
    Facing the same error message I soled it with the command: docker network create -d bridge --subnet 172.16.57.0/24 roachnet
  • Maxime La-x
    Maxime La-x almost 2 years
    Same with Cisco Anyconnect on Ubuntu
  • bonafernando
    bonafernando almost 2 years
    Confirmed here. You saved me from starting running unknown commands.
  • Chang Zhao
    Chang Zhao over 1 year
    yes, it solved for me too, but how can we have openvpn running and still not get this error?
  • wlarcheveque
    wlarcheveque over 1 year
    I had the same problem having a NordVPN connection active. I disconnected from the VPN and reconnected after launching the docker containers.
  • Md Atiqul Haque
    Md Atiqul Haque over 1 year
    Also, solve for me after off the open vpn connection.

Related