If you have already created a docker-compose stack and you are trying to restart the containers or start them 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.
- Docker Compose
Step 1. Firstly check the
docker-compose.yml file if you have some 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 still getting the same error the final step is to shut down the containers, remove them all and restart the docker daemon:
- Shut down the docker compose containers:
- Remove all containers:
docker rm $(docker ps -qa)
docker system prune
- 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.
If you 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.