Conversation
- Detect missing Docker binary via PATH check - Detect daemon unavailability via direct client connection failure - Detect permission issues via socket access checks - Provide clear, actionable error messages - Avoid fragile error-string parsing entirely - Use argparse parser.error() for clean CLI exits Tested scenarios: - Normal operation - Docker socket permission denied - Docker daemon stopped - Recovery after restoring permissions
Baseline: normal operationrocker ubuntu:22.04 echo NORMAL_OK image builds and container runs successfullyPermission denied: socket inaccessiblesudo chmod 600 /var/run/docker.sock clean CLI error, permission issue detected, actionable fix suggestedDocker daemon stoppedsudo systemctl stop docker.socket docker.service daemon unavailability detected, clear diagnostic shown, no tracebackRecovery after restoring system statesudo chmod 666 /var/run/docker.sock normal operation restored |
src/rocker/core.py
Outdated
| client = docker.from_env().api | ||
| except AttributeError: | ||
| # docker-py pre 2.0 | ||
| docker_client = docker.Client() | ||
| # Validate that the server is available | ||
| docker_client.ping() | ||
| return docker_client | ||
| except (docker.errors.DockerException, docker.errors.APIError, ConnectionError) as ex: | ||
| raise DependencyMissing('Docker Client failed to connect to docker daemon.' | ||
| ' Please verify that docker is installed and running.' | ||
| ' As well as that you have permission to access the docker daemon.' | ||
| ' This is usually by being a member of the docker group.' | ||
| ' The underlying error was:\n"""\n%s\n"""\n' % ex) | ||
| client = docker.Client() | ||
|
|
||
| client.ping() | ||
| return client | ||
|
|
There was a problem hiding this comment.
These lines appear to be unchanged except for a variable rename and some lost comments. Can you revert them to the original for better visibility.
src/rocker/core.py
Outdated
| "Fix:\n" | ||
| f" sudo usermod -aG docker {user}\n" | ||
| " log out and log back in" | ||
| ) |
There was a problem hiding this comment.
It would be better to move these into the error processing instead of running the checks every time.
The effort of things like the deferred import won't be useful if these debug paths are hit on startup every time. These three detectors could be run in the except block below before the raise on line 264 https://github.com/osrf/rocker/pull/343/changes#diff-2fe1df65d4c2adbc967d2d5fd30aff95ab3b70d956f1bc4b6f5ff3f6bf881b4aR264
|
Great, please see my inline requests above about small cleanups. |
- Move Docker checks into exception block (only run on failure) - Restore original variable names (docker_client not client) - Restore original comments (docker-py pre 2.0, etc) - Remove separate helper functions to reduce diff noise This addresses both review comments on PR osrf#343: 1. Minimal diff by preserving unchanged code structure 2. Better performance by only running checks when needed All error messages and user experience remain identical.
|
@tfoote Thank you for the clear feedback! I've made both requested changes: 1. Restored original code structure:
2. Moved diagnostics to exception handler:
The new flow:
All error messages and user experience remain identical. Ready for re-review! |
tfoote
left a comment
There was a problem hiding this comment.
Thanks for reducing this down. As it's only in the exception processing I'm not going to insist on test coverage.
|
@tfoote Thanks again for the review and for merging this — it was a great experience working through the feedback. If there are any adjacent areas you’d recommend improving (around rocker or elsewhere in the repo) for someone interested in contributing longer-term, I’d be happy to help where it’s most useful. |
|
I'd suggest looking at the good first issues tag on issues: https://github.com/osrf/rocker/issues?q=is%3Aissue%20state%3Aopen%20label%3A%22good%20first%20issue%22 A lower level one might be #35 which will need to find a way to capture the build output and present it. The underlying capture mechanism isn't clearly defined. Or something a ilttle bit more about creating a helpful tool for users is integrating Dive #310 It looks like it could be a new default extension that exposes the capabilities of dive to rocker users. |
Summary
This PR improves Docker error handling by using direct, measurable
system checks instead of parsing Docker error strings.
It addresses the long-standing issue in #34 and incorporates the
feedback and intent from the discussion in #334.
Detection logic
The following failure modes are detected explicitly:
/var/run/docker.sockAll errors are reported via
argparse.parser.error()for clean CLI exits.Why this approach
core.pyTested scenarios