Skip to content

Prevent rc.docker from trying to start up non-unRAID containers#2610

Open
andrebrait wants to merge 1 commit intounraid:masterfrom
andrebrait:patch-1
Open

Prevent rc.docker from trying to start up non-unRAID containers#2610
andrebrait wants to merge 1 commit intounraid:masterfrom
andrebrait:patch-1

Conversation

@andrebrait
Copy link
Copy Markdown

@andrebrait andrebrait commented Apr 8, 2026

  • Docker Compose handles its own startup
  • Both unRAID and Compose use the net.unraid.docker.managed label, but with different values
  • unRAID trying to start Compose containers may cause them to fail to start
  • This commit fixes the behavior above by only attempting to manage dockerman-managed containers

Summary by CodeRabbit

  • Bug Fixes
    • Improved container identification and filtering logic for more accurate recognition of managed containers.
    • Enhanced status detection for container operations including availability checks, start, and stop commands.

* Docker Compose handles its own startup
* Both unRAID and Compose use the `net.unraid.docker.managed` label, but with different values
* unRAID trying to start Compose containers may cause them to fail to start
* This commit fixes the behavior above by only attempting to manage dockerman-managed containers
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Apr 8, 2026

Walkthrough

Updated all_containers() and running_containers() functions in the Docker rc.d script to filter and list only containers labeled with net.unraid.docker.managed=dockerman. The change restricts which containers are recognized as "managed" for downstream start/stop operations.

Changes

Cohort / File(s) Summary
Docker Management Filtering
etc/rc.d/rc.docker
Modified all_containers() and running_containers() to filter containers by the label net.unraid.docker.managed=dockerman, restricting container discovery to managed instances only.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Poem

🐰 A script so keen, with labels so bright,
Filters the docker with precision so tight,
Only the managed ones hop through our sight,
Organization complete, everything's right! 🏷️✨

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title directly and specifically describes the main change in the changeset: preventing rc.docker from managing non-unRAID containers by filtering to only dockerman-managed containers.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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
Contributor

@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

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@etc/rc.d/rc.docker`:
- Around line 160-165: The docker listing commands are using grep (which does
substring matches) causing false positives; update both docker container ls
invocations (the one before the "Running containers" comment and the
running_containers() function) to use Docker's label filter instead of grep: add
--filter 'label=net.unraid.docker.managed=dockerman' to docker container ls,
remove the grep and keep/adjust the --format to output just '{{.Names}}' (so you
can drop the awk '{print $1}' step), ensuring exact key=value label matching and
no substring matches.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: cb98b71f-d822-4b27-8892-a261bcc6e94f

📥 Commits

Reviewing files that changed from the base of the PR and between 7756908 and 46116f5.

📒 Files selected for processing (1)
  • etc/rc.d/rc.docker

Comment on lines +160 to +165
docker container ls -a --format='{{.Names}} {{.Labels}}' 2>/dev/null | grep 'net.unraid.docker.managed=dockerman' | awk '{print $1}'
}

# Running containers
running_containers(){
docker ps --format='{{.Names}} {{.Labels}}' 2>/dev/null | grep 'net.unraid.docker.managed=' | awk '{print $1}'
docker container ls --format='{{.Names}} {{.Labels}}' 2>/dev/null | grep 'net.unraid.docker.managed=dockerman' | awk '{print $1}'
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Verify grep regex pitfalls with current pattern:
set -euo pipefail

pattern='net.unraid.docker.managed=dockerman'

printf '%s\n' \
  'ok net.unraid.docker.managed=dockerman,foo=bar' \
  'bad1 netXunraidXdockerXmanaged=dockerman,foo=bar' \
  'bad2 net.unraid.docker.managed=dockerman-extra,foo=bar' \
| grep "$pattern" || true

echo "Expected: current grep matches all 3 lines; only first should be considered managed."
echo "Using docker --filter label=... avoids this class of mismatch."

Repository: unraid/webgui

Length of output: 355


🏁 Script executed:

cd /root/webgui && wc -l etc/rc.d/rc.docker

Repository: unraid/webgui

Length of output: 119


🏁 Script executed:

cd /root/webgui && sed -n '155,170p' etc/rc.d/rc.docker

Repository: unraid/webgui

Length of output: 119


🏁 Script executed:

#!/bin/bash
# Test Docker label filtering behavior (simulation with echo):

# Simulate docker container ls output with labels
docker_output='
container1
container2
container3
'

echo "=== Testing grep with current pattern ==="
printf '%s\n' \
  'mycontainer net.unraid.docker.managed=dockerman,other=value' \
  'badcontainer net.unraid.docker.managed=dockerman-extra,other=value' \
  'othercontainer some.other.label=value' \
| grep 'net.unraid.docker.managed=dockerman' && echo "Matched above (should be 2 but may be 1)" || true

echo ""
echo "=== Testing grep with -F (literal) flag ==="
printf '%s\n' \
  'mycontainer net.unraid.docker.managed=dockerman,other=value' \
  'badcontainer net.unraid.docker.managed=dockerman-extra,other=value' \
  'othercontainer some.other.label=value' \
| grep -F 'net.unraid.docker.managed=dockerman' && echo "Matched above" || true

echo ""
echo "=== Checking if Docker supports --filter with label= ==="
docker container ls --help 2>/dev/null | grep -A 5 '\--filter' | head -20

Repository: unraid/webgui

Length of output: 510


🏁 Script executed:

git ls-files | grep -E '(rc\.docker|etc/rc\.d)' | head -20

Repository: unraid/webgui

Length of output: 423


🏁 Script executed:

git ls-files | xargs grep -l 'all_containers\|running_containers' 2>/dev/null | head -5

Repository: unraid/webgui

Length of output: 75


🏁 Script executed:

cat -n etc/rc.d/rc.docker | sed -n '155,170p'

Repository: unraid/webgui

Length of output: 611


🏁 Script executed:

# Test Docker --filter with label syntax
docker container ls --help 2>&1 | grep -A 10 'filter' | head -20

Repository: unraid/webgui

Length of output: 39


🌐 Web query:

Docker container ls --filter label exact match behavior documentation

💡 Result:

For docker container ls / docker ps, the label filter only supports:

  • Key present: --filter "label=color" matches containers that have the color label, regardless of value. [1]
  • Exact key=value: --filter "label=color=blue" matches containers whose color label value is exactly blue (it’s not documented as doing partial/substring or regex matching for label values). [1]

Docker labels are stored/compared as strings (Docker doesn’t deserialize structured values like JSON for “querying/filtering by label value”). [3]

If you need substring/regex-like behavior, Docker’s general filter docs note that some filters support partial/regex matching but this is command/filter-specific—so you generally have to post-filter the output (e.g., --format … | grep/jq) when the label filter isn’t expressive enough. [2]

Sources
[1] Docker CLI reference: docker container ls (Filtering / label) (docs.docker.com)
[2] Docker Docs: “Filter commands” (some filters exact vs partial vs regex; command-specific) (docs.docker.com)
[3] Docker Docs: “Docker object labels” (labels are strings; no deserialization for querying/filtering) (docs.docker.com)

Citations:


Use Docker label filters instead of grep to avoid substring matching false positives.

Lines 160 and 165 use grep 'net.unraid.docker.managed=dockerman' which matches substrings (e.g., dockerman-extra). This can re-include unintended containers, undermining the PR's goal.

Docker's native --filter 'label=net.unraid.docker.managed=dockerman' performs exact key=value matching and is the correct approach.

Proposed fix
 all_containers(){
-  docker container ls -a --format='{{.Names}} {{.Labels}}' 2>/dev/null | grep 'net.unraid.docker.managed=dockerman' | awk '{print $1}'
+  docker container ls -a --filter 'label=net.unraid.docker.managed=dockerman' --format='{{.Names}}' 2>/dev/null
 }
 
 # Running containers
 running_containers(){
-  docker container ls --format='{{.Names}} {{.Labels}}' 2>/dev/null | grep 'net.unraid.docker.managed=dockerman' | awk '{print $1}'
+  docker container ls --filter 'label=net.unraid.docker.managed=dockerman' --format='{{.Names}}' 2>/dev/null
 }
📝 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
docker container ls -a --format='{{.Names}} {{.Labels}}' 2>/dev/null | grep 'net.unraid.docker.managed=dockerman' | awk '{print $1}'
}
# Running containers
running_containers(){
docker ps --format='{{.Names}} {{.Labels}}' 2>/dev/null | grep 'net.unraid.docker.managed=' | awk '{print $1}'
docker container ls --format='{{.Names}} {{.Labels}}' 2>/dev/null | grep 'net.unraid.docker.managed=dockerman' | awk '{print $1}'
all_containers(){
docker container ls -a --filter 'label=net.unraid.docker.managed=dockerman' --format='{{.Names}}' 2>/dev/null
}
# Running containers
running_containers(){
docker container ls --filter 'label=net.unraid.docker.managed=dockerman' --format='{{.Names}}' 2>/dev/null
}
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@etc/rc.d/rc.docker` around lines 160 - 165, The docker listing commands are
using grep (which does substring matches) causing false positives; update both
docker container ls invocations (the one before the "Running containers" comment
and the running_containers() function) to use Docker's label filter instead of
grep: add --filter 'label=net.unraid.docker.managed=dockerman' to docker
container ls, remove the grep and keep/adjust the --format to output just
'{{.Names}}' (so you can drop the awk '{print $1}' step), ensuring exact
key=value label matching and no substring matches.

@andrebrait
Copy link
Copy Markdown
Author

I found a bug when restoring user networks. Will update the script with the fix.

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.

1 participant