Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Detect snap docker #22

Merged
merged 1 commit into from
Jun 1, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down
Loading