Skip to content

[docker-outside-of-docker] Add alwaysUseSocketProxy option - #1761

Open
aremily wants to merge 2 commits into
devcontainers:mainfrom
aremily:docker-outside-of-docker-always-socket-proxy
Open

aremily wants to merge 2 commits into
devcontainers:mainfrom
aremily:docker-outside-of-docker-always-socket-proxy

Conversation

@aremily

@aremily aremily commented Nov 1, 2026 •

Copy link
Copy Markdown

Summary

Adds an opt-in alwaysUseSocketProxy option (default false) that always uses the Feature's
existing socat proxy instead of changing the GID of the container's docker group with
groupmod. Behavior is unchanged when the option is off. Version bump 1.10.1 -> 1.11.0.

Problem

When the host socket's GID is nonzero and not used by any group in the container, docker-init.sh
runs groupmod --gid <socket gid> docker. That updates /etc/group but not the supplementary
groups of processes that are already running, so they keep getting EACCES on the socket.

The dev container CLI (checked in 0.90.0) starts the container as:

/bin/sh -c 'echo Container started
trap "exit 0" 15
/usr/local/share/docker-init.sh      # Feature entrypoints, called with no arguments
exec "$@"                            # the image's entrypoint/cmd when overrideCommand is false
while sleep 1 & wait $!; do :; done' -

That wrapper shell starts before groupmod and keeps its old groups, as does anything it execs.
Processes started later (docker exec, terminals, lifecycle commands) get fresh groups and are not
affected. That is why tests that run in a new process do not catch this.

Observed here (host socket GID 997, container docker group 999):

  • wrapper shell (PID 1) groups: 999 1000
  • docker ps as a fresh process: works
  • docker ps with exactly the wrapper's groups: permission denied while trying to connect to the docker API at unix:///var/run/docker.sock

Change

  • devcontainer-feature.json: new alwaysUseSocketProxy boolean, version 1.11.0.
  • install.sh: reads the option and adds it to the condition that selects the groupmod branch.
    With it set, the existing proxy branch runs. The proxy socket is owned by the user, so no group
    membership is needed.
  • README.md / NOTES.md: option documented, including the docker-outside-of-docker: socat breaks interactive support #483 limitation (see below).
  • Test scenario socket_proxy_always (see below).

Why opt-in

The default (auto) stays as it is: where groupmod works, /var/run/docker.sock is the host's own
socket, with no extra process or hop. The proxy replaces it with a separate socket owned by the user
(mode 660), adds a long-lived socat process, and has its own failure modes, so existing users should
not get it unless they ask. This option changes nothing for anyone who does not set it.

The proxy also has a known defect today: socat drops output that arrives after the client stops
sending (#483; reproduced: echo "sleep 2; uname; exit 2" | docker run -i ubuntu bash prints nothing
through the proxy). That affects the existing fallback too, and it is fixed in the related PR below.

Related PR

#1762, "[docker-outside-of-docker] Fix socat proxy dropping delayed output" (fixes #483), is stacked on this
branch. The two address different problems and either is useful without the other. #1762 is stacked
because its regression test needs the proxy to be in use, and this option's scenario
(socket_proxy_always) is the only deterministic way to do that. Until #1762 lands, NOTES.md here
mentions #483; #1762 removes that note. Both bump the Feature version (1.11.0 here, 1.11.1 in #1762), so
expect a small rebase if one merges first.

Testing

devcontainer features test -f docker-outside-of-docker locally (arm64 host, Docker 29.9.2, CLI 0.90.0):
all autogenerated tests and all scenarios pass except docker_dash_compose_v1 and
docker_dash_compose_v1_moby, which fail with error: externally-managed-environment (pip) and fail
identically on unmodified main.

New scenario socket_proxy_always (mcr.microsoft.com/devcontainers/base:ubuntu-24.04,
containerUser: vscode, alwaysUseSocketProxy: true). It has two parts.

  1. Stale groups. A fresh process hides the bug, so the script takes the groups of the container's own
    command (/proc/<pid>/status) and runs docker ps through sudo setpriv with exactly those groups.
    It also checks that the socket is a real socket, socat runs with the expected arguments, the log says
    "Enabling socket proxy", and a plain docker ps works.
  2. Proxy selection. Whether the host socket's GID would pick groupmod depends on the host (GID 0 or a GID
    already in the image picks the proxy anyway), so the script builds a fixture: a socket owned by an unused
    GID (4242) that forwards to the real socket. The host socket is not touched. It runs a path-rewritten
    copy of the generated docker-init.sh against it. With the option on, the proxy starts, the docker
    group's GID is unchanged, the proxy socket is owned by the user, and docker ps works through it. A
    control run with the condition flipped to false takes the groupmod path (the group's GID becomes 4242)
    and does not start the proxy.

I checked that the scenario fails when the option's condition is removed from install.sh, including with
the checks from part 1 disabled, so part 2 catches it on its own. The test matches the literal
[ "true" != "true" ] in the generated script; a change to that line makes the
control-condition-present-in-generated-script check fail rather than pass silently.

Not tested: other base images in test-pr.yaml, x86_64 hosts, and an end-to-end overrideCommand: false
(Compose) container. The latter is expected to hit the issue from reading the CLI source.

Related

When the host Docker socket's GID is nonzero and unused in the container,
the entrypoint changes the GID of the container's docker group with
groupmod. That does not update the supplementary groups of processes that
are already running, so they keep getting EACCES on the socket. With the
dev container CLI this includes the wrapper shell that runs the entrypoint
and then execs the image command (overrideCommand: false). Processes
started later (docker exec, terminals) get fresh groups and are not
affected, which is why tests that run in a new process do not catch it.

Add an opt-in alwaysUseSocketProxy option (default false) that skips the
groupmod branch and always uses the existing socat proxy, whose target
socket is owned by the user and needs no group membership. Behavior is
unchanged when the option is off.

The proxy has a known limitation (devcontainers#483), so it stays opt-in.

Add the socket_proxy_always scenario. It inspects the container's own
command (not a fresh process) and runs docker with that process's group
list. The same check fails with the default configuration.
@aremily
aremily requested a review from a team as a code owner November 1, 2026 02:26
@aremily

aremily commented Nov 1, 2026

Copy link
Copy Markdown
Author

aremily please read the following Contributor License Agreement(CLA). If you agree with the CLA, please reply with the following information.

@microsoft-github-policy-service agree [company="{your company}"]

Options:

  • (default - no company specified) I have sole ownership of intellectual property rights to my Submissions and I am not making Submissions in the course of work for my employer.
@microsoft-github-policy-service agree
  • (when company given) I am making Submissions in the course of work for my employer (or my employer has intellectual property rights in my Submissions by contract or applicable law). I have permission from my employer to make Submissions and enter into this Agreement on behalf of my employer. By signing below, the defined term “You” includes me and my employer.
@microsoft-github-policy-service agree company="Microsoft"

Contributor License Agreement

Contribution License Agreement

This Contribution License Agreement (“Agreement”) is agreed to by the party signing below (“You”), and conveys certain license rights to Microsoft Corporation and its affiliates (“Microsoft”) for Your contributions to Microsoft open source projects. This Agreement is effective as of the latest signature date below.

  1. Definitions.
    “Code” means the computer software code, whether in human-readable or machine-executable form,
    that is delivered by You to Microsoft under this Agreement.
    “Project” means any of the projects owned or managed by Microsoft and offered under a license
    approved by the Open Source Initiative (www.opensource.org).
    “Submit” is the act of uploading, submitting, transmitting, or distributing code or other content to any
    Project, including but not limited to communication on electronic mailing lists, source code control
    systems, and issue tracking systems that are managed by, or on behalf of, the Project for the purpose of
    discussing and improving that Project, but excluding communication that is conspicuously marked or
    otherwise designated in writing by You as “Not a Submission.”
    “Submission” means the Code and any other copyrightable material Submitted by You, including any
    associated comments and documentation.
  2. Your Submission. You must agree to the terms of this Agreement before making a Submission to any
    Project. This Agreement covers any and all Submissions that You, now or in the future (except as
    described in Section 4 below), Submit to any Project.
  3. Originality of Work. You represent that each of Your Submissions is entirely Your original work.
    Should You wish to Submit materials that are not Your original work, You may Submit them separately
    to the Project if You (a) retain all copyright and license information that was in the materials as You
    received them, (b) in the description accompanying Your Submission, include the phrase “Submission
    containing materials of a third party:” followed by the names of the third party and any licenses or other
    restrictions of which You are aware, and (c) follow any other instructions in the Project’s written
    guidelines concerning Submissions.
  4. Your Employer. References to “employer” in this Agreement include Your employer or anyone else
    for whom You are acting in making Your Submission, e.g. as a contractor, vendor, or agent. If Your
    Submission is made in the course of Your work for an employer or Your employer has intellectual
    property rights in Your Submission by contract or applicable law, You must secure permission from Your
    employer to make the Submission before signing this Agreement. In that case, the term “You” in this
    Agreement will refer to You and the employer collectively. If You change employers in the future and
    desire to Submit additional Submissions for the new employer, then You agree to sign a new Agreement
    and secure permission from the new employer before Submitting those Submissions.
  5. Licenses.
  • Copyright License. You grant Microsoft, and those who receive the Submission directly or
    indirectly from Microsoft, a perpetual, worldwide, non-exclusive, royalty-free, irrevocable license in the
    Submission to reproduce, prepare derivative works of, publicly display, publicly perform, and distribute
    the Submission and such derivative works, and to sublicense any or all of the foregoing rights to third
    parties.
  • Patent License. You grant Microsoft, and those who receive the Submission directly or
    indirectly from Microsoft, a perpetual, worldwide, non-exclusive, royalty-free, irrevocable license under
    Your patent claims that are necessarily infringed by the Submission or the combination of the
    Submission with the Project to which it was Submitted to make, have made, use, offer to sell, sell and
    import or otherwise dispose of the Submission alone or with the Project.
  • Other Rights Reserved. Each party reserves all rights not expressly granted in this Agreement.
    No additional licenses or rights whatsoever (including, without limitation, any implied licenses) are
    granted by implication, exhaustion, estoppel or otherwise.
  1. Representations and Warranties. You represent that You are legally entitled to grant the above
    licenses. You represent that each of Your Submissions is entirely Your original work (except as You may
    have disclosed under Section 3). You represent that You have secured permission from Your employer to
    make the Submission in cases where Your Submission is made in the course of Your work for Your
    employer or Your employer has intellectual property rights in Your Submission by contract or applicable
    law. If You are signing this Agreement on behalf of Your employer, You represent and warrant that You
    have the necessary authority to bind the listed employer to the obligations contained in this Agreement.
    You are not expected to provide support for Your Submission, unless You choose to do so. UNLESS
    REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING, AND EXCEPT FOR THE WARRANTIES
    EXPRESSLY STATED IN SECTIONS 3, 4, AND 6, THE SUBMISSION PROVIDED UNDER THIS AGREEMENT IS
    PROVIDED WITHOUT WARRANTY OF ANY KIND, INCLUDING, BUT NOT LIMITED TO, ANY WARRANTY OF
    NONINFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
  2. Notice to Microsoft. You agree to notify Microsoft in writing of any facts or circumstances of which
    You later become aware that would make Your representations in this Agreement inaccurate in any
    respect.
  3. Information about Submissions. You agree that contributions to Projects and information about
    contributions may be maintained indefinitely and disclosed publicly, including Your name and other
    information that You submit with Your Submission.
  4. Governing Law/Jurisdiction. This Agreement is governed by the laws of the State of Washington, and
    the parties consent to exclusive jurisdiction and venue in the federal courts sitting in King County,
    Washington, unless no federal subject matter jurisdiction exists, in which case the parties consent to
    exclusive jurisdiction and venue in the Superior Court of King County, Washington. The parties waive all
    defenses of lack of personal jurisdiction and forum non-conveniens.
  5. Entire Agreement/Assignment. This Agreement is the entire agreement between the parties, and
    supersedes any and all prior agreements, understandings or communications, written or oral, between
    the parties relating to the subject matter hereof. This Agreement may be assigned by Microsoft.

@microsoft-github-policy-service agree

Copilot AI left a comment

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.

🟡 Changes recommended

The new scenario can pass even if the proxy-option condition is removed, so a deterministic unused, nonzero socket GID fixture is needed to verify the intended behavior.

2 open issues
What changed in this PR

Adds an opt-in alwaysUseSocketProxy option to avoid Docker socket permission failures in processes that retain their original supplementary groups. Default behavior remains unchanged.

Changes:

  • Adds the boolean option and bumps the Feature version to 1.11.0.
  • Routes enabled configurations through the existing socat proxy and documents its limitations.
  • Adds a scenario checking proxy operation and Docker access with the container command’s group list.
File Description
test/​docker-outside-of-docker/​socket_proxy_always.sh Checks proxy setup and socket access with startup groups.
test/​docker-outside-of-docker/​scenarios.json Adds a scenario enabling the proxy option.
src/​docker-outside-of-docker/​README.md Lists the new option and its default.
src/​docker-outside-of-docker/​NOTES.md Explains stale-group permissions and the proxy limitation.
src/​docker-outside-of-docker/​install.sh Bypasses groupmod when the option is enabled.
src/​docker-outside-of-docker/​devcontainer-feature.json Declares the option and updates the version.

Review effort: Balanced

if [ "${ENABLE_NONROOT_DOCKER}" = "true" ] && [ "${SOURCE_SOCKET}" != "${TARGET_SOCKET}" ] && [ "${USERNAME}" != "root" ] && [ "${USERNAME}" != "0" ]; then
SOCKET_GID=\$(stat -c '%g' ${SOURCE_SOCKET})
if [ "\${SOCKET_GID}" != "0" ] && [ "\${SOCKET_GID}" != "${DOCKER_GID}" ] && ! grep -E ".+:x:\${SOCKET_GID}" /etc/group; then
if [ "${ALWAYS_USE_SOCKET_PROXY}" != "true" ] && [ "\${SOCKET_GID}" != "0" ] && [ "\${SOCKET_GID}" != "${DOCKER_GID}" ] && ! grep -E ".+:x:\${SOCKET_GID}" /etc/group; then

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Agreed, thanks. Fixed in cc68071.

socket_proxy_always now builds a fixture instead of depending on the host socket's GID: a socket owned by
an unused, nonzero GID (4242) that forwards to the real socket. The host socket is not touched. The script
runs a path-rewritten copy of the generated docker-init.sh against it. A fixture-socket-created check
makes the test fail with a clear message if the fixture socket does not appear.

  • Option on: the proxy starts ("Enabling socket proxy" in the log), the docker group's GID is unchanged,
    the proxy socket is owned by the user, and docker ps works through it.
  • Control, condition flipped to false: the same fixture takes the groupmod path (the group's GID becomes
    4242) and the proxy does not start. This shows the fixture really would select groupmod.

I also checked that the scenario fails when the option's condition is removed from install.sh, including
with the older checks disabled, so the new checks catch it on their own.

One caveat: the test matches the literal [ "true" != "true" ] in the generated script to flip the
condition. If that line changes (for example #1749 rewrites the if), the
control-condition-present-in-generated-script check fails instead of passing silently, and the test needs
updating.

Comment thread src/docker-outside-of-docker/NOTES.md Outdated
}
```

> **Note:** `socat` can drop output from `docker run --interactive` when input arrives with pauses in it ([#483](https://github.com/devcontainers/features/issues/483)). This is why the proxy is opt-in.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Agreed, you are right that it is not about pauses in input. Fixed in cc68071.

The note now says that the Docker CLI closes its write side right after sending a request, that socat
then waits only 0.5 s before dropping the connection, and that this affects docker run and docker exec
with or without --interactive (with the sleep 5; date example). It also says the same applies when the
Feature falls back to the proxy on its own, so users can weigh it before enabling the option.

While in that section I also added one sentence saying the option has no effect when the remote user is
root, because root can use the socket directly and only a stub entrypoint is installed.

#1762 fixes the cause with socat -t 31536000 and removes this note, so the wording here only needs to be
correct until that lands.

… GID

The scenario could pass without the option because a host socket with GID 0 or a GID already in the image selects the proxy anyway. Build a fixture socket owned by an unused GID, run a path-rewritten copy of the generated docker-init.sh against it, and assert that the option keeps the docker group's GID and starts the proxy. A control run with the condition flipped must take the groupmod path. Also describe delayed output after the client closes its write side in NOTES.md.

This branch has not been deployed

No deployments
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.

docker-outside-of-docker: socat breaks interactive support

2 participants