Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
]
}
},

"mounts": [
"source=/etc/machine-id,target=/etc/machine-id,ro,type=bind,consistency=cached"
],
Comment on lines +36 to +38

Choose a reason for hiding this comment

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

P1 Badge Avoid unconditional mount of host machine-id

The new mounts entry assumes /etc/machine-id exists on the host, but many contributors use Docker Desktop on macOS or Windows where that file is absent. In those environments docker run will refuse to start the dev container because the bind source does not exist, rendering the default devcontainer unusable. This solves the WSL case but regresses other platforms; consider making the mount optional or creating the file when present instead of requiring it globally.

Useful? React with 👍 / 👎.

Comment on lines +36 to +38
Copy link

@coderabbitai coderabbitai bot Nov 3, 2025

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🔴 Critical

🧩 Analysis chain

Verify devcontainer mounts behavior when /etc/machine-id is absent.

The new mounts configuration binds /etc/machine-id from the host into the container. This directly addresses the stated problem of unstable machine-id in the test environment. However, confirm the following:

  1. Syntax correctness: Verify the mount string format is valid for devcontainer (it appears correct, but consult official devcontainer spec if unsure).
  2. Host file existence: Clarify the behavior if /etc/machine-id does not exist on the host system—will the container fail to start, or will the mount silently fail/be skipped?
  3. Alternative locations: The PR description notes some systems have machine-id in /var/lib/dbus/machine-id. Consider whether a second mount entry would improve robustness, or document this known limitation.

The fix looks sound for the target environment (WSL/devcontainer). Run this verification to confirm the mount syntax is correct per the devcontainer specification:


🏁 Script executed:

#!/bin/bash
# Description: Verify the mounts syntax in devcontainer.json against the spec.

# Check if the JSON is valid
jq empty .devcontainer/devcontainer.json && echo "JSON is valid"

# Extract and display the mounts section for manual inspection
jq '.mounts' .devcontainer/devcontainer.json

Length of output: 113


🏁 Script executed:

#!/bin/bash
# Display the first ~10 lines to identify the parse error at line 5, col 4
echo "=== First 15 lines of devcontainer.json ==="
head -15 .devcontainer/devcontainer.json

echo -e "\n=== Lines 30-45 (mounts section) ==="
sed -n '30,45p' .devcontainer/devcontainer.json

echo -e "\n=== Full file with line numbers ==="
cat -n .devcontainer/devcontainer.json

Length of output: 2340






🌐 Web query:

devcontainer.json mounts syntax specification format

💡 Result:

Short answer

  • In devcontainer.json, "mounts" is an array. Each entry may be:
    • A string using Docker CLI --mount syntax (key=value pairs separated by commas): e.g. "source=/host/path,target=/container/path,type=bind,consistency=cached". [1]
    • Or a JSON object with fields like type, source, target (and optional bind/volume/tmpfs options): e.g. { "type": "volume", "source": "my-vol", "target": "/data" }. [2]

Notes

  • The string form accepts the same options as Docker's --mount (and supports VS Code variable interpolation like ${localEnv:...} and ${localWorkspaceFolder}). [1][3]
  • Use bind for host paths, volume for named volumes, tmpfs for tmpfs, etc.; consistency/read_only and other mount-specific options follow Docker semantics. [1][2]

Sources
[1] VS Code / devcontainers docs (mount examples and --mount string form).
[2] microsoft/vscode devcontainers examples & issues (object-form example and fields).
[3] VS Code docs / metadata reference (notes on interpolation and behavior).


🌐 Web query:

devcontainer.json comments support JSON5

💡 Result:

Short answer: Yes — devcontainer.json supports comments, but via JSONC (JSON with comments), not necessarily full JSON5 syntax. Use // or /* */ comments and keep the file as JSONC; if you run a linter, set its file type to JSONC (not strict JSON). [1][2][3]

Sources:

  • VS Code / Dev Containers docs: devcontainer.json is "JSONC (JSON with comments)". [1]
  • GitHub Codespaces docs: devcontainer.json written using JSONC; linters should be set to JSONC. [2]
  • JSON5 spec (for comparison): JSON5 allows comments plus other extensions (unquoted keys, trailing commas, etc.). [3]


---

🌐 Web query:

```web
Docker devcontainer bind mount fails if source file missing behavior

💡 Result:

Short answer

  • Docker bind mounts require the host path (file or directory) to exist when using --mount (the daemon will error if the source is missing). VS Code Dev Containers passes mounts through to Docker, so you get the same failure. [1][2][3]
  • Behavior differences: the legacy -v/--volume syntax will create a missing host path (as a directory) in some cases; the --mount long form will not — it errors instead. For swarm services a host bind path must exist on every node. [3][2]
    What to do
  • Create the file/path on the host before opening the devcontainer (mkdir/touch or a prep script), or use a named Docker volume/volume mount instead of a host-file bind if you need automatic creation. [4][2]

Sources

  1. VS Code / devcontainer example showing Docker error when source empty. [turn0search0]
  2. "Invalid mount config for type 'bind': bind source path does not exist" — documentation/answers explaining host path must exist (and swarm behavior). [turn1search0]
  3. Explanation of difference between -v/--volume and --mount (--mount does not auto-create; -v may). [turn1search4]
  4. Practical guidance (create file beforehand / scripts) and examples. [turn1search3]

Docker bind mount will fail container startup if /etc/machine-id is missing on the host.

The mount syntax is valid per devcontainer specification, using correct Docker --mount format. However, Docker's --mount (used by Dev Containers) requires the source path to exist on the host—if /etc/machine-id is absent, the devcontainer will error during startup rather than silently skip the mount.

This breaks the devcontainer for systems without /etc/machine-id (noted in the PR as a known limitation on some systems). Consider:

  • Document the requirement clearly in README or devcontainer.json comments so users on affected systems understand they need to create the file.
  • Use a named volume instead of a bind mount if a fallback for missing host files is needed.
  • Add a setup script to create /etc/machine-id if missing (though this may not align with the read-only intent).
🤖 Prompt for AI Agents
.devcontainer/devcontainer.json lines 36-38: the current bind mount of
/etc/machine-id will cause container startup to fail on hosts where that file
doesn't exist; update the setup to avoid a hard host bind or document the
requirement. Fix options: (1) replace the host bind with a named volume (e.g.,
source=devcontainer-machine-id,type=volume,target=/etc/machine-id) and add a
postStartCommand or Dockerfile step to populate the file inside the container if
the volume is empty; or (2) remove the mount and document in README that
/etc/machine-id must exist on the host before starting the devcontainer (with
clear creation instructions), or (3) add a devcontainer postCreateCommand script
that checks for /etc/machine-id and creates it on the host prior to mounting (if
you choose to keep the bind) — implement one of these fixes and update
devcontainer.json and README accordingly.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I think this is an important issue to resolve @dietWall

Copy link

Choose a reason for hiding this comment

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

Seems like the humans are having a chat. I'll hop back into my burrow for now. If you need me again, just tag @coderabbitai in a new comment, and I'll come hopping out!

Copy link
Author

Choose a reason for hiding this comment

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

@patrick-stephens
Thanks for feedback, I also think that this is serious and not a good solution yet, I don´t want to break build environments for other systems. Therefore it stalled the last days.

I am looking right now how it could be solved in other ways, as I couldn´t find something like a conditional mount in devcontainers documentation.

I can think of multiple different solutions, like setup function for this test, postCreateCommand in devcontainer or change the test. But I have to implement it to see if its working.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I thought we had added some unit tests around this in the Calyptia days to allow you to specify machine ID, etc. as well explicitly - using /etc/machine-id is not recommended for lots of reasons not just that it may not be there :)

Copy link
Collaborator

Choose a reason for hiding this comment

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

This was my PR I was thinking of: #9691

Maybe instead of mounting things in it would be better to support an override we can then set for the container.

Copy link
Author

Choose a reason for hiding this comment

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

I see.

After taking a quick look at PR #9691, I think I can reuse at least the test setup functions here. Probably even more, I need to carefully go through this changes.

Right now I like the idea to generate a new machine-id if it not exists and reuse it later. If it exists, no generation is required.

I would submit a new PR in the next days, as it changes the concept quite a lot. So we can close this one.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yeah, relying on machine-id is a bad thing in general as you've seen :)

Copy link
Collaborator

Choose a reason for hiding this comment

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

I'll let you close to make it clear there is a new approach

"remoteUser": "fluent-bit"
}
Loading