Update /etc/hosts when linked container is restarted

Carry of #7092

closes #7092
fixes #6350

/cc @vieux
This is some super deep nesting.
Could we change these ifs to be the other way
```go
if cid == "0" {
  return nil
}
```
etc, on down the line.