diff --git a/cmd/root.go b/cmd/root.go index e9749bf..258858f 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -90,11 +90,33 @@ func init() { rootCommand.AddCommand(newDiagnosticsCommand()) } +func isDockerSnap() bool { + cli, err := client.NewClientWithOpts(client.FromEnv, client.WithAPIVersionNegotiation()) + if err != nil { + log.Fatalf("Unable to initialize Docker client: %s", err) + } + + defer cli.Close() // Close the client when the function returns (should not be needed, but just to be safe) + + info, err := cli.Info(context.Background()) + if err != nil { + log.Fatalf("Unable to get Docker info: %s", err) + } + + // Check if Docker root directory contains '/var/snap/docker' + return strings.Contains(info.DockerRootDir, "/var/snap/docker") +} + func rootCmdRun(cmd *cobra.Command, _ []string) { printLogo() log.Debug("running in debug mode") log.WithField("config_file", configPath).Info("loading configuration from file") + if isDockerSnap() { + log.Error("Docker Snap installation detected. Exiting...") + os.Exit(1) + } + if ok, _ := cmd.Flags().GetBool("ignore-certificate-errors"); ok { log.Warn("running with --ignore-certificate-errors: TLS certificate host chains and name will not be verified") http.DefaultTransport.(*http.Transport).TLSClientConfig = &tls.Config{