docker-compose Fails After Network Is Removed

Today I run into a strange problem concerning docker-compose. I have several stacks defined in my developer environment. For some reason I removed old networks with the command

docker network prune

After that I was no longer able to start my aplications with docker-compose up:

docker-compose up
Creating network "myapp_default" with the default driver
Starting myapp_app_1 …
Starting myapp-db_1 … error
ERROR: for myapp-db_1 Cannot start service myapp-db: network 656be42244ac96cd35bf7fb786

The problem was that docker-compose created a new default network, but this was not defined for the already existing containers. Containers always connect to networks using the network ID which is guaranteed to be unique. And this ID was now no longer valid. 

One solution is to remove all existing containers maunally. A better solution is to shut down the conainers  with the command

$ docker-compose down

This will remove the internal Network IDs and you can restart the containers again with

$ docker-compose up

Leave a Reply

Your email address will not be published. Required fields are marked *