2023-04-04 16:32:04 +03: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 07:00:04 +03:00
|
|
|
func CheckIfDockerRunning(ctx context.Context, configDockerHost string) error {
|
2023-06-18 08:38:38 +03:00
|
|
|
opts := []client.Opt{
|
|
|
|
client.FromEnv,
|
|
|
|
}
|
|
|
|
|
2023-06-30 07:00:04 +03:00
|
|
|
if configDockerHost != "" {
|
|
|
|
opts = append(opts, client.WithHost(configDockerHost))
|
2023-06-18 08:38:38 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
cli, err := client.NewClientWithOpts(opts...)
|
2023-04-04 16:32:04 +03:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
defer cli.Close()
|
|
|
|
|
|
|
|
_, err = cli.Ping(ctx)
|
|
|
|
if err != nil {
|
2024-05-03 10:54:34 +03:00
|
|
|
return fmt.Errorf("cannot ping the docker daemon. is it running? %w", err)
|
2023-04-04 16:32:04 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|