Docker-下调 default_network 错误

我有一个 docker-与一些 php,mysql 等组成开始。几天后,我不能把他们下来,因为一切停止,而不是 mysql。它总是给我以下错误:

ERROR: network docker_default has active endpoints

这是我的码头作品

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告诉我:

[
{
"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": {}
}
]

更新

看起来 docker rm mysql -f停止了 mysql 容器,但是网络正在运行。

删除了与 docker network disconnect -f docker_default mysql的网络,但我很感兴趣,我是如何进入这种情况。有什么想法?

88423 次浏览

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.

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

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

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>

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

This worked for me. systemctl restart docker

service docker restart

then remove the network normally

docker network rm [network name]