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 {
|
|
|
|
return fmt.Errorf("cannot ping the docker daemon, does it running? %w", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|