117

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?

8
  • 1
    What's still running on the network? docker network inspect docker_default should list the containers. Is mysql really left justified in your yml and not spaced in?
    – BMitch
    Mar 16, 2017 at 18:40
  • 1
    Also see if you currently have containers running: docker container ls -a Mar 16, 2017 at 18:43
  • @BMitch I updated the question and no mysql is not left justified, was my fault in the question.
    – Flo
    Mar 16, 2017 at 18:49
  • @nateleavitt mysql is running
    – Flo
    Mar 16, 2017 at 18:49
  • Any reason you can see that mysql is refusing to stop? Can you stop it manually, any logs available? Please include output from the command line when you attempt to stop it.
    – BMitch
    Mar 16, 2017 at 18:52

8 Answers 8

131

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
85

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.

8
  • 4
    no I didn't edit the compose file while running. I did really nothing. thought my webserver was up and running. but sometimes I had issues connecting to the wordpress. because of database issues. then I tried to get it down and my question started...
    – Flo
    Mar 16, 2017 at 19:10
  • Okay.. does it seem to be operating normally now? Mar 16, 2017 at 19:54
  • It may be a sleep issue. Sometimes things can get out of sync when mac sleeps. There is currently a time issue with macs right now, but I'm not even sure you're running a mac. I usually do a docker-compose down at the end of my day. Mar 16, 2017 at 19:56
  • This command didn't work in my case, but docker-compose stop container_id helped Nov 10, 2020 at 18:52
  • 2
    In my case, docker inspect network didn't show any active Containers for this network. Restarting docker and running a docker system prune --all removed the network and things worked again. Mar 25, 2022 at 19:34
50

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>
2
  • 11
    In our case there are not any endpoint in inspect.
    – Dzenly
    Sep 27, 2021 at 16:24
  • 2
    I had the same issue, no endpoints. docker system prune - helped
    – Max
    Dec 17, 2021 at 16:31
11

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

5

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
1
  • 5
    docker-compose up --remove-orphans to remove leftover containers
    – jamesbcn
    Jul 22, 2020 at 9:28
5

This worked for me. systemctl restart docker

2
  • Being on a mac makes this, at least for me, a little bit difficult. Restarting my docker desktop is pretty much the same as command, and that worked well enough.
    – naiJenn
    Jun 29, 2022 at 1:57
  • In case someone needs to do this on a mac on cli: killall Docker && open /Applications/Docker.app Sep 15, 2022 at 8:16
0

service docker restart

then remove the network normally

docker network rm [network name]

0

This issue happens rarely while running exceptional dozens of services ( in parallel ) on the same instance, but unfortunately docker-compose could not establish deployment / recreation operation of these containers as a result of an "active network interface" that is bind and stuck.

I also enabled running flags such as:

  • force-recreate ( Recreate containers even if their configuration and image haven’t changed ) or
  • remove-orphans flags(Remove containers for services not defined in the Compose file.)

but it did not help.

Eventually I came into conclusion that restarting docker engine is the last resort - docker closes any network connections that are associated with the docker daemon ( connection between containers and between the api )- this action solved this problem ( sudo service docker restart )

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.