docker,

How to fix Docker error: 'Cannot start service .. network $network-id not found

Nov 18, 2021 · 1 min read · Post a comment

If you have already created a Docker Compose stack and you are trying to start/restart the containers, you may face Docker error: Cannot start service ..: network $network-id not found error. Here I will quickly show you some working scenarios on how to fix it.

Prerequisites

  • Docker
  • Docker Compose

Solution

Step 1. First, check docker-compose.yml file for any network dependencies.

version: '3'
services:
...
networks:
  default:
    driver: bridge
  db:
    driver: bridge
  elk:
    external:
      name: elastic-search

Here in the example above you can see that we have an external network that is linked to another service. You will have to check if the ELK stack is started and that network is created already. If not, you should create it.

Step 2. If step 1 is not your case, next you can check if there are some old container instances that were not removed.

docker container ls -a

If you spot some old containers that you are not using you can remove them with:

docker container rm $container_id
docker container rm $container_id

Step 3. If you’re still getting the same error the final step is to shut down the containers, remove them all and restart the Docker daemon.

Step 3.1. Shut down the Docker Compose containers:

docker-compose down

Step 3.2. Remove all containers:

docker rm $(docker ps -qa)

Or, use:

docker system prune

Step 3.3. Restart the Docker daemon:

systemctl restart docker.service

These steps will help you to re-create the networks and run the containers without network issues.

Conclusion

If you are still struggling to fix the error please don’t hesitate to put a comment below with the error details. Feel free to leave a comment below and if you find this tutorial useful, follow our official channel on Telegram.