docker-compose down default_network error

DockerDocker Compose

Docker Problem Overview


I have a docker-compose with some php, mysql and so on starting. After a few days, I cannot bring them down as everything stopps instead of mysql. It always gives me the following error:

ERROR: network docker_default has active endpoints

this is my docker-compose.yml

version: '2'
services:
  php:
    build: php-docker/.
    container_name: php
    ports:
      - "9000:9000"
    volumes:
      - /var/www/:/var/www/
    links:
      - mysql:mysql
    restart: always

  nginx:
    build: nginx-docker/.
    container_name: nginx
    links:
      - php
      - mysql:mysql
    environment:
      WORDPRESS_DB_HOST: mysql:3306
    ports:
      - "80:80"

    volumes:
      - /var/log/nginx:/var/log/nginx
      - /var/www/:/var/www/
      - /var/logs/nginx:/var/logs/nginx
      - /var/config/nginx/certs:/etc/nginx/certs
      - /var/config/nginx/sites-enabled:/etc/nginx/sites-available
    restart: always

  mysql:
    build: mysql-docker/.
    container_name: mysql
    volumes:
      - /var/mysql:/var/lib/mysql
    environment:
      MYSQL_ROOT_PASSWORD: pw
      MYSQL_USER: florian
      MYSQL_PASSWORD: pw
      MYSQL_DATABASE: database
    restart: always


  phpmyadmin:
    build: phpmyadmin/.
    links:
     - mysql:db
    ports:
     - 1234:80
    container_name: phpmyadmin
    environment:
     PMA_ARBITRARY: 1
     PMA_USERNAME: florian
     PMA_PASSWORD: pw
     MYSQL_ROOT_PASSWORD: pw
    restart: always

docker network inspect docker_default gives me:

[
    {
        "Name": "docker_default",
        "Id": "1ed93da1a82efdab065e3a833067615e2d8b76336968a2591584af5874f07622",
        "Created": "2017-03-08T07:21:34.969179141Z",
        "Scope": "local",
        "Driver": "bridge",
        "EnableIPv6": false,
        "IPAM": {
            "Driver": "default",
            "Options": null,
            "Config": [
                {
                    "Subnet": "172.18.0.0/16",
                    "Gateway": "172.18.0.1"
                }
            ]
        },
        "Internal": false,
        "Attachable": false,
        "Containers": {
            "85985605f1c0c20e5ee9fedc95800327f782beafc0049f51e645146d2e954b7d": {
                "Name": "mysql",
                "EndpointID": "84fb19cd428f8b0ba764b396362727d9809cd1cfea536e648bfc4752c5cb6b27",
                "MacAddress": "02:42:ac:12:00:03",
                "IPv4Address": "172.18.0.3/16",
                "IPv6Address": ""
            }
        },
        "Options": {},
        "Labels": {}
    }
]

UPDATE

Seems that docker rm mysql -f stopped the mysql container, but the network is running.

Removed the network with docker network disconnect -f docker_default mysql But I'm pretty interested in how I got into this situation. any ideas?

Docker Solutions


Solution 1 - Docker

I'm guessing you edited the docker-compose file while you were currently running...?

Sometimes if you edit the docker-compose file before doing a docker-compose down it will then have a mismatch in what docker-compose will attempt to stop. First run docker rm 8598560 to stop the currently running container. From there, make sure you do a docker-compose down before editing the file. Once you stop the container, docker-compose up should work.

Solution 2 - Docker

I resolved a similar problem when I added this after rename services in by docker-compose.yml file before stop container

docker-compose down --remove-orphans

Solution 3 - Docker

You need to disconnect stale endpoint(s) from the network. First, get the endpoint names with

docker network inspect <network>

You can find your endpoints in the output JSON: Containers -> Name. Now, simply force disconnect them with:

docker network disconnect -f <network> <endpoint>

Solution 4 - Docker

Unfortunately none of above worked for me. Restarting the docker service solved the problem.

Solution 5 - Docker

I happened to run into this error message because I had two networks with the same name (copy/paste mistake).

What I did to fix it:

  • docker-compose down - ignore errors
  • docker network list - note if any container is using it and stop if if necessary
  • docker network prune to remove all dangling networks, although you may want to just docker network rm <network name>
  • rename the second network to a unique name
  • docker-compose up

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionFlorianView Question on Stackoverflow
Solution 1 - DockernateleavittView Answer on Stackoverflow
Solution 2 - DockerAlex KView Answer on Stackoverflow
Solution 3 - DockerTomasz BartkowiakView Answer on Stackoverflow
Solution 4 - DockerProsunjit BiswasView Answer on Stackoverflow
Solution 5 - DockerSebView Answer on Stackoverflow