| 80 | } |
| 81 | |
| 82 | func (d dockerRuntime) Start(ctx context.Context) error { |
| 83 | a := d.Init(ctx) |
| 84 | |
| 85 | a.Retry("", time.Second, 60, func(int) error { |
| 86 | return d.systemctl.Start("docker.service") |
| 87 | }) |
| 88 | |
| 89 | // service startup takes few seconds, retry for a minute before giving up. |
| 90 | a.Retry("", time.Second, 60, func(int) error { |
| 91 | return d.guest.RunQuiet("sudo", "docker", "info") |
| 92 | }) |
| 93 | |
| 94 | // ensure docker is accessible without root |
| 95 | // otherwise, restart to ensure user is added to docker group |
| 96 | a.Add(func() error { |
| 97 | if err := d.guest.RunQuiet("docker", "info"); err == nil { |
| 98 | return nil |
| 99 | } |
| 100 | ctx := context.WithValue(ctx, cli.CtxKeyQuiet, true) |
| 101 | return d.guest.Restart(ctx) |
| 102 | }) |
| 103 | |
| 104 | return a.Exec() |
| 105 | } |
| 106 | |
| 107 | func (d dockerRuntime) Running(ctx context.Context) bool { |
| 108 | return d.systemctl.Active("docker.service") |