Skip to content

fix: smarter container engine detection in lint-container.sh#441

Merged
qhkm merged 1 commit intomainfrom
fix/smarter-container-detection
Mar 26, 2026
Merged

fix: smarter container engine detection in lint-container.sh#441
qhkm merged 1 commit intomainfrom
fix/smarter-container-detection

Conversation

@qhkm
Copy link
Copy Markdown
Owner

@qhkm qhkm commented Mar 25, 2026

Summary

  • Replaces "prefer Podman" logic from fix: prefer Podman in lint-container.sh (#424) #426 with smarter auto-detection
  • Docker stays the default for real Docker users
  • Detects Podman-as-Docker via docker info | grep podman and switches to podman directly to avoid buildx driver issues
  • CONTAINER_ENGINE env var override still bypasses everything

Closes #435

Test plan

  • Real Docker + Podman installed → picks Docker
  • CONTAINER_ENGINE=podman override → picks Podman
  • Podman-as-Docker system → picks podman directly (cc @taqtiqa-mark)

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Chores
    • Improved container engine detection in the build process for enhanced compatibility across different containerization environments.

Replaces the "prefer Podman" logic from #426 with smarter auto-detection:
Docker first, but if Docker CLI is actually a Podman alias, use podman
directly to avoid buildx driver issues.

Closes #435

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Mar 25, 2026

📝 Walkthrough

Walkthrough

The detect_engine() function in scripts/lint-container.sh was updated to reverse engine preference back to Docker while adding logic to detect and handle "Podman-as-Docker" scenarios. The new approach runs docker info first, checks if the output contains "podman", and switches to Podman directly if detected—avoiding compatibility issues with buildx's docker-container driver.

Changes

Cohort / File(s) Summary
Container Engine Detection
scripts/lint-container.sh
Updated detect_engine() function to prefer Docker by default, with added detection for Podman masquerading as Docker. If Podman is detected via docker info grep, the script switches to Podman directly. Control flow now returns early after engine selection, with nested checks for Docker CLI aliasing.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~15 minutes

Possibly related PRs

Poem

🐰 A rabbit hops through Docker's gate,
But waits to check—is this my fate?
Is Podman wearing Docker's face?
The grep will tell, right here, this place!
Now engines dance in their right place. 🎭

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'fix: smarter container engine detection in lint-container.sh' accurately summarizes the main change: improving container engine detection logic in the specified script.
Linked Issues check ✅ Passed The pull request implements all coding objectives from issue #435: Docker-first detection, Podman-as-Docker detection via 'docker info | grep podman', direct podman invocation when masqueraded, fallback to Podman, and CONTAINER_ENGINE override preservation.
Out of Scope Changes check ✅ Passed All changes are within scope: the pull request modifies only the container engine detection logic in scripts/lint-container.sh with no unrelated alterations to exported entities or external functionality.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/smarter-container-detection

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (2)
scripts/lint-container.sh (2)

47-47: Redundant stderr redirection and double docker info invocation.

&>/dev/null already redirects both stdout and stderr, so 2>&1 is redundant. Additionally, docker info is executed twice—once in the condition check (line 47) and again for the grep (line 48). Consider caching the output to avoid the duplicate call.

♻️ Suggested improvement
-  if command -v docker &>/dev/null && docker info &>/dev/null 2>&1; then
-    if docker info 2>/dev/null | grep -qi podman; then
+  if command -v docker &>/dev/null; then
+    local docker_info
+    docker_info=$(docker info 2>/dev/null) || true
+    if [ -n "$docker_info" ]; then
+      if echo "$docker_info" | grep -qi podman; then

(You'll need to adjust the closing braces/fi accordingly.)

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@scripts/lint-container.sh` at line 47, The conditional currently calls docker
info twice and uses redundant redirection; change it to call docker info once,
capture its output/status into a variable (e.g., DOCKER_INFO or docker_info)
with stderr redirected once, then use command -v docker && [ -n "$DOCKER_INFO" ]
(or test the captured output) and reuse that variable for the subsequent grep
instead of invoking docker info again; update the if/fi block accordingly so
only a single docker info call is made and remove the redundant 2>&1
redirection.

45-62: Inconsistent engine-selection priority with container-base.sh.

The relevant context snippet shows that scripts/container-base.sh (sourced by bench-container.sh, fix-container.sh, and test-container.sh) uses Podman-first logic, while this script now uses Docker-first logic. This inconsistency could surprise users who expect uniform behavior across the container scripts.

If the Docker-first approach is intentional for linting due to buildx requirements, consider documenting this divergence in the script header or unifying the detection logic into a shared helper.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@scripts/lint-container.sh` around lines 45 - 62, The lint-container engine
detection uses Docker-first while container-base uses Podman-first, causing
inconsistent behavior; either make lint-container follow the same Podman-first
priority (change the Docker-first detection block to the same logic used in
container-base) or extract the selection logic into a shared helper function
(e.g., detect_container_engine) that both lint-container and container-base
call; if Docker-first is intentional for linting, add a short header comment in
lint-container explaining the divergence and reference the shared helper
location.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@scripts/lint-container.sh`:
- Around line 48-56: When the check docker info | grep -qi podman detects
Podman-as-Docker but command -v podman fails, do not fall back to echoing
"docker"; instead emit a clear warning/error and exit non-zero so callers know
the environment is unsupported. Update the branch that currently runs after the
command -v podman check (the block following docker info | grep -qi podman) to
log a descriptive message (e.g., "Podman detected as docker CLI but no
standalone podman binary found; buildx incompatible") and exit 1 rather than
returning "docker", keeping the existing successful path (echo "podman")
unchanged.

---

Nitpick comments:
In `@scripts/lint-container.sh`:
- Line 47: The conditional currently calls docker info twice and uses redundant
redirection; change it to call docker info once, capture its output/status into
a variable (e.g., DOCKER_INFO or docker_info) with stderr redirected once, then
use command -v docker && [ -n "$DOCKER_INFO" ] (or test the captured output) and
reuse that variable for the subsequent grep instead of invoking docker info
again; update the if/fi block accordingly so only a single docker info call is
made and remove the redundant 2>&1 redirection.
- Around line 45-62: The lint-container engine detection uses Docker-first while
container-base uses Podman-first, causing inconsistent behavior; either make
lint-container follow the same Podman-first priority (change the Docker-first
detection block to the same logic used in container-base) or extract the
selection logic into a shared helper function (e.g., detect_container_engine)
that both lint-container and container-base call; if Docker-first is intentional
for linting, add a short header comment in lint-container explaining the
divergence and reference the shared helper location.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: cd9da1fa-4cc0-4456-b5aa-9fdb09c7ad9c

📥 Commits

Reviewing files that changed from the base of the PR and between 7868357 and 8fe1f70.

📒 Files selected for processing (1)
  • scripts/lint-container.sh

Comment thread scripts/lint-container.sh
Comment on lines +48 to 56
if docker info 2>/dev/null | grep -qi podman; then
# Docker CLI is actually a Podman alias — use podman directly
if command -v podman &>/dev/null; then
echo "podman"
return
fi
fi
echo "docker"
return
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Edge case: Podman-as-Docker detected but no standalone podman binary.

When Podman masquerades as Docker but no separate podman binary exists (line 50 fails), the code falls through to line 55 and returns "docker". This still invokes the Podman-aliased docker CLI, which the PR aims to avoid due to buildx driver networking issues (#424, #435).

Consider logging a warning or erroring out in this scenario, since the buildx compatibility problem will likely persist.

💡 Possible approach
       if command -v podman &>/dev/null; then
         echo "podman"
         return
       fi
+      echo "Warning: Docker CLI is Podman alias, but 'podman' binary not found; buildx issues may occur" >&2
     fi
     echo "docker"
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if docker info 2>/dev/null | grep -qi podman; then
# Docker CLI is actually a Podman alias — use podman directly
if command -v podman &>/dev/null; then
echo "podman"
return
fi
fi
echo "docker"
return
if docker info 2>/dev/null | grep -qi podman; then
# Docker CLI is actually a Podman alias — use podman directly
if command -v podman &>/dev/null; then
echo "podman"
return
fi
echo "Warning: Docker CLI is Podman alias, but 'podman' binary not found; buildx issues may occur" >&2
fi
echo "docker"
return
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@scripts/lint-container.sh` around lines 48 - 56, When the check docker info |
grep -qi podman detects Podman-as-Docker but command -v podman fails, do not
fall back to echoing "docker"; instead emit a clear warning/error and exit
non-zero so callers know the environment is unsupported. Update the branch that
currently runs after the command -v podman check (the block following docker
info | grep -qi podman) to log a descriptive message (e.g., "Podman detected as
docker CLI but no standalone podman binary found; buildx incompatible") and exit
1 rather than returning "docker", keeping the existing successful path (echo
"podman") unchanged.

@qhkm qhkm merged commit 3e1130e into main Mar 26, 2026
14 checks passed
@qhkm qhkm deleted the fix/smarter-container-detection branch March 26, 2026 07:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix: smarter container engine detection in lint-container.sh

1 participant