diff --git a/bin/si/src/args.rs b/bin/si/src/args.rs index 552df0378c..87df88f8b6 100644 --- a/bin/si/src/args.rs +++ b/bin/si/src/args.rs @@ -54,6 +54,11 @@ pub(crate) struct Args { #[arg(value_parser = PossibleValuesParser::new(Engine::variants()))] #[arg(long, short, env = "SI_CONTAINER_ENGINE", default_value = "docker")] engine: String, + /// A path to a docker.sock file. The default paths checked are `/var/run/docker.sock` + /// and `$HOME/.docker/run/docker.sock"`. Passing a value here will be an explicit + /// usage of that location. + #[arg(long, env = "SI_DOCKER_SOCK")] + pub docker_sock: Option, #[command(subcommand)] pub(crate) command: Commands, } diff --git a/bin/si/src/main.rs b/bin/si/src/main.rs index f97e427a58..786d05eb8f 100644 --- a/bin/si/src/main.rs +++ b/bin/si/src/main.rs @@ -23,6 +23,12 @@ async fn main() -> Result<()> { let mode = args.mode(); let is_preview = args.is_preview; + let docker_sock = if let Some(sock) = args.docker_sock.clone() { + sock + } else { + "".to_string() + }; + let current_version = VERSION.trim(); debug!(arguments =?args, "parsed cli arguments"); @@ -41,14 +47,21 @@ async fn main() -> Result<()> { std::path::Path::new("/var/run/docker.sock").to_path_buf(), ]; - let docker_socket = docker_socket_candidates - .iter() - .find(|candidate| candidate.exists()) - .ok_or(eyre!( - "failed to determine Docker socket location; candidates={docker_socket_candidates:?}" + let docker: DockerClient; + if let "" = docker_sock.as_str() { + let socket = docker_socket_candidates + .iter() + .find(|candidate| candidate.exists()) + .ok_or(eyre!( + "failed to determine Docker socket location. Set a custom location using `--docker-sock` \ + or `SI_DOCKER_SOCK`; candidates={docker_socket_candidates:?}" ))?; - - let docker = DockerClient::unix(docker_socket); + docker = DockerClient::unix(socket) + } else { + println!("Checking for user supplied docker.sock"); + let path = std::path::Path::new(docker_sock.as_str()).to_path_buf(); + docker = DockerClient::unix(path); + } let state = AppState::new( ph_client,