R/validate-container.R

Defines functions validate_container_available

Documented in validate_container_available

#' Validate a container engine is available
#'
#' Checks that Docker or Podman is installed and can be executed.
#'
#' @param preference Character string or NULL. Preferred engine.
#' @return Invisible character string with the engine name.
#' @keywords internal
validate_container_available <- function(preference = NULL) {
  engine <- detect_container_engine(preference)

  if (is.null(engine)) {
    cli::cli_abort(c(
      "Neither Docker nor Podman was found on the system",
      "i" = "Install Docker: {.url https://docs.docker.com/get-docker/}",
      "i" = "Install Podman: {.url https://podman.io/getting-started/installation}"
    ))
  }

  tryCatch({
    result <- processx::run(engine, c("info"),
                            error_on_status = FALSE, timeout = 15)
    if (result$status != 0) {
      cli::cli_abort(c(
        "{.strong {engine}} is installed but not running",
        "i" = "Start the {engine} daemon and try again",
        "x" = "Error: {result$stderr}"
      ))
    }
  }, error = function(e) {
    cli::cli_abort(c(
      "{.strong {engine}} was found but could not be executed",
      "x" = "Error: {e$message}"
    ))
  })

  invisible(engine)
}

Try the shinyelectron package in your browser

Any scripts or data that you put into this service are public.

shinyelectron documentation built on Dec. 3, 2026, 9:07 a.m.