Skip to content

fix(project): run docker as host user with project dir group#1097

Open
bdgraue (bdgraue) wants to merge 1 commit into
shopware:nextfrom
bdgraue:fix/docker-host-user-mapping
Open

fix(project): run docker as host user with project dir group#1097
bdgraue (bdgraue) wants to merge 1 commit into
shopware:nextfrom
bdgraue:fix/docker-host-user-mapping

Conversation

@bdgraue

Copy link
Copy Markdown

Fixes #1096
Refs shopware/shopware#15896

Problem

project create --docker and project dev fail with "Permission denied" for any host user whose UID is not 1000 (composer cannot write composer.lock during create; system:install cannot write var/log during dev). The ghcr.io/shopware/docker-dev image runs as UID 1000, and on Linux bind mounts expose raw host ownership, so the containers cannot write into a project directory owned by any other user. See #1096 for full details.

Approach

Run the containers as the calling host user (Linux only):

  • internal/system/docker_unix.go: IsDockerMountable() no longer hard-codes os.Getuid() == 1000 — with user mapping in place, bind mounts are writable for any host user. New helpers: ProjectUserSpec(dir) returns the uid:gid spec (caller's UID + the project directory's owning group), DockerRunUserArgs(projectDir) returns the docker run arguments (--user plus HOME/COMPOSER_HOME pointed at a writable location, since an arbitrary UID has no passwd entry inside the image).
  • cmd/project/project_create_install.go: the composer docker run gets those user arguments.
  • internal/docker/compose.go: ComposeOptions gains a User field, emitted as user: on the web service; WriteComposeFile defaults it to ProjectUserSpec(projectFolder). All existing WriteComposeFile callers (project create, project dev, dev TUI) pick this up automatically.

Using the project directory's owning group as the GID keeps shared, group-owned multi-user dev directories working (e.g. a setgid projects dir owned by a dev group): files created by the container stay writable for the whole group.

The mapping is deliberately Linux-only (ProjectUserSpec returns "" elsewhere): on macOS and Windows, Docker Desktop's VM handles bind-mount ownership, so the containers keep running with the image default user there and existing behavior is unchanged.

Testing

  • Two new sub-tests in internal/docker/compose_test.go cover the user: key emission (set vs. unset).
  • gofmt, go build ./..., golangci-lint run --timeout 4m and the test suites for internal/docker, internal/system and cmd/project all pass locally.
  • Verified locally against 0.16.0-alpha-3 on Ubuntu (host UID 1001).

Open question for review

Whether the docker-dev image entrypoint starts cleanly as an arbitrary uid:gid (no passwd entry inside the container) — I will post the result of the first docker compose up with the generated user: key in this PR.

🤖 Generated with Claude Code

`project create --docker` and `project dev` fail with "Permission denied"
for host users with a UID other than 1000: the docker-dev image runs as
UID 1000 and cannot write to the bind-mounted project directory.

Run the containers as the calling host user instead: the composer
`docker run` gets `--user uid:gid` plus HOME/COMPOSER_HOME pointed at a
writable location (an arbitrary UID has no passwd entry in the image),
and the generated compose.yaml sets `user:` on the web service. The GID
is taken from the project directory's owning group so shared,
group-owned multi-user dev directories keep working. The mapping is
Linux-only: Docker Desktop's VM handles ownership on macOS/Windows.

Fixes shopware#1096
Refs shopware/shopware#15896

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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