2023-04-04 08:32:04 -05: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-29 23:00:04 -05:00
|
|
|
func CheckIfDockerRunning(ctx context.Context, configDockerHost string) error {
|
2023-06-18 00:38:38 -05:00
|
|
|
opts := []client.Opt{
|
|
|
|
client.FromEnv,
|
|
|
|
}
|
|
|
|
|
2023-06-29 23:00:04 -05:00
|
|
|
if configDockerHost != "" {
|
|
|
|
opts = append(opts, client.WithHost(configDockerHost))
|
2023-06-18 00:38:38 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
cli, err := client.NewClientWithOpts(opts...)
|
2023-04-04 08:32:04 -05: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
|
|
|
|
}
|