From ded441cf75a837ff55e51333234232284f1bd221 Mon Sep 17 00:00:00 2001 From: Sergio <77530549+sergi0g@users.noreply.github.com> Date: Thu, 2 Jan 2025 12:47:52 +0200 Subject: [PATCH] Add support for connecting with both unix and http docker sockets. Hasn't been tested yet. --- src/docker.rs | 33 +++++++++++++++++++++++---------- 1 file changed, 23 insertions(+), 10 deletions(-) diff --git a/src/docker.rs b/src/docker.rs index cd8b319..af90896 100644 --- a/src/docker.rs +++ b/src/docker.rs @@ -6,20 +6,33 @@ use crate::{config::Config, error, structs::image::Image}; fn create_docker_client(socket: Option<&String>) -> Docker { let client: Result = match socket { - Some(sock) => Docker::connect_with_local( - sock, - 120, - &ClientVersion { - major_version: 1, - minor_version: 44, - }, - ), - None => Docker::connect_with_local_defaults(), + Some(sock) => { + if sock.starts_with("unix://") { + Docker::connect_with_unix( + sock, + 120, + &ClientVersion { + major_version: 1, + minor_version: 44, + }, + ) + } else { + Docker::connect_with_http( + sock, + 120, + &ClientVersion { + major_version: 1, + minor_version: 44, + }, + ) + } + } + None => Docker::connect_with_unix_defaults(), }; match client { Ok(d) => d, - Err(e) => error!("Failed to connect to docker socket!\n{}", e), + Err(e) => error!("Failed to connect to docker daemon!\n{}", e), } }