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?

Upvotes: 2

Views: 6140

Answers (3)

louxiu
louxiu

Reputation: 2915

  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

Upvotes: 2

After deleting the network the id of the deleted network is given in the output. We can recreate the same network using that id:

docker network create "deleted_network_id"

after the recreation connect that network to the container:

docker network connect "network_id" "container"

Upvotes: 6

vimscape
vimscape

Reputation: 11

Maybe this works:

docker run -itd --network=networkName containerName

https://docs.docker.com/engine/reference/commandline/network_connect/

Upvotes: 0

Related Questions