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