fussybeaver / bollard

Docker daemon API in Rust
Apache License 2.0
814 stars 127 forks source link

Add Docker Socket availability check during connection creation #383

Closed patrickap closed 3 weeks ago

patrickap commented 4 months ago

Currently, the connect_with_ methods return a type of Result<Docker, Error> without performing any availability check. This means that even if the Docker Socket is not available, the method returns Ok() instead of Err().

For example, when attempting to connect using Docker::connect_with_socket_defaults(), if /var/run/docker.sock is not available, it still returns Ok() instead of Err().

To improve usability and prevent unexpected behavior, I propose adding an availability check during connection creation. This check should verify the availability of the Docker Socket and return an error if it's not accessible.

let docker = match Docker::connect_with_socket_defaults() {
  Ok(docker) => docker,
  Err(err) => {
    eprintln!("failed to connect to docker daemon: {:?}", err);
    return;
  }
};
bpmooch commented 4 months ago

As a workaround, I've been calling docker.ping() immediately after creating the connection

fussybeaver commented 4 months ago

Hmm.. thanks for reporting, let's check first that this isn't a regression from the previous version, because quite a lot changed with the hyper 1.x upgrade

fussybeaver commented 4 months ago

Can confirm, this is not a regression, happy if you can add this as a feature