fix(docker-exec-via-sock): 改进错误信息展示和命令执行逻辑

This commit is contained in:
严浩
2025-09-23 11:09:42 +08:00
parent 400591498c
commit 05cfe833da

View File

@@ -72,8 +72,8 @@ docker_exec_create() {
docker_exec_create_id=$(printf '%s' "$DOCKER_LAST_RESPONSE" | jq -r '.Id // empty') docker_exec_create_id=$(printf '%s' "$DOCKER_LAST_RESPONSE" | jq -r '.Id // empty')
if [ -z "$docker_exec_create_id" ]; then if [ -z "$docker_exec_create_id" ]; then
log "failed to create $docker_exec_create_desc exec for $CONTAINER_NAME" error_message=$(printf '%s' "$DOCKER_LAST_RESPONSE" | jq -r '.message // "unknown error"')
log "docker response: $DOCKER_LAST_RESPONSE" log "failed to create $docker_exec_create_desc exec for $CONTAINER_NAME: $error_message"
return 1 return 1
fi fi
@@ -189,13 +189,13 @@ fi
log "starting exec $exec_id" log "starting exec $exec_id"
if ! start_output=$(docker_exec_start "$exec_id" "exec"); then start_output=$(docker_exec_start "$exec_id" "exec") || true
exit 1
fi
if ! exit_code=$(docker_exec_exit_code "$exec_id"); then if ! exit_code=$(docker_exec_exit_code "$exec_id"); then
log "could not determine exec exit code" error_message=$(printf '%s' "$DOCKER_LAST_RESPONSE" | jq -r '.message // "unknown error"')
log "docker inspect response: $DOCKER_LAST_RESPONSE" 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 exit 1
fi fi