Search code examples
dockercontainersdocker-network

Is it possible to restart a docker container that had its network removed?


I tried to remove a docker network that is connected to a container, but couldn't because the container is running. I then stopped the container and removed the network. When I tried to restart the container, it errored:
Error response from daemon: Cannot restart container my_container: network aa15e9d00da5e769af8305e25807973691e25032f0c0a6c76c84fb37446a4ff5 not found

I tried to connect to different networks but I can't. Is there any way to restart the container again now that the original network has been removed?


Solution

    1. Recreate the network with the same name and get it's id.
    2. Edit container's config.v2.json, update the NetworkID with the new id in NetworkSettings.Networks
    3. Restart docker service and restart the container