From 020859ff16508cb2b8f5eb6936bf767d84f58359 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=A5=E6=B5=A9?= Date: Tue, 23 Sep 2025 11:11:16 +0800 Subject: [PATCH] =?UTF-8?q?fix(docker-exec-via-sock):=20=E5=A2=9E=E5=BC=BA?= =?UTF-8?q?=E5=91=BD=E4=BB=A4=E6=89=A7=E8=A1=8C=E9=94=99=E8=AF=AF=E5=A4=84?= =?UTF-8?q?=E7=90=86=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docker-exec-via-sock.sh | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/docker-exec-via-sock.sh b/docker-exec-via-sock.sh index ad631f4..9547ec0 100644 --- a/docker-exec-via-sock.sh +++ b/docker-exec-via-sock.sh @@ -84,14 +84,16 @@ docker_exec_start() { docker_exec_start_id=$1 docker_exec_start_desc=$2 docker_exec_start_endpoint="${docker_api_base}/exec/${docker_exec_start_id}/start" - DOCKER_LAST_RESPONSE=$(curl --fail --show-error --silent --unix-socket "$DOCKER_SOCKET" \ + if ! DOCKER_LAST_RESPONSE=$(curl --fail --show-error --silent --unix-socket "$DOCKER_SOCKET" \ -X POST \ -H "Content-Type: application/json" \ -d '{"Detach": false, "Tty": true}' \ - "$docker_exec_start_endpoint") + "$docker_exec_start_endpoint"); then + log "command execution failed. output from container: $DOCKER_LAST_RESPONSE" + return 1 + fi log_stream "$docker_exec_start_desc output" "$DOCKER_LAST_RESPONSE" - printf '%s' "$DOCKER_LAST_RESPONSE" } @@ -189,13 +191,14 @@ fi log "starting exec $exec_id" -start_output=$(docker_exec_start "$exec_id" "exec") || true +if ! start_output=$(docker_exec_start "$exec_id" "exec"); then + # The error is already logged inside docker_exec_start + exit 1 +fi if ! exit_code=$(docker_exec_exit_code "$exec_id"); then error_message=$(printf '%s' "$DOCKER_LAST_RESPONSE" | jq -r '.message // "unknown error"') log "could not determine exec exit code: $error_message" - log "this often happens if the command inside the container fails immediately (e.g. command not found)." - log "initial command output from container: $start_output" exit 1 fi