2023-04-04 13:32:04 +00:00
|
|
|
// Copyright 2023 The Gitea Authors. All rights reserved.
|
|
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
|
|
|
|
package envcheck
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
"github.com/docker/docker/client"
|
|
|
|
)
|
|
|
|
|
2023-06-30 04:00:04 +00:00
|
|
|
func CheckIfDockerRunning(ctx context.Context, configDockerHost string) error {
|
2023-06-18 05:38:38 +00:00
|
|
|
opts := []client.Opt{
|
|
|
|
client.FromEnv,
|
|
|
|
}
|
|
|
|
|
2023-06-30 04:00:04 +00:00
|
|
|
if configDockerHost != "" {
|
|
|
|
opts = append(opts, client.WithHost(configDockerHost))
|
2023-06-18 05:38:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
cli, err := client.NewClientWithOpts(opts...)
|
2023-04-04 13:32:04 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
defer cli.Close()
|
|
|
|
|
|
|
|
_, err = cli.Ping(ctx)
|
|
|
|
if err != nil {
|
2024-05-03 07:54:34 +00:00
|
|
|
return fmt.Errorf("cannot ping the docker daemon. is it running? %w", err)
|
2023-04-04 13:32:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|