Skip to content

fix(project): support running shopware-cli inside the docker dev container#1100

Open
bdgraue (bdgraue) wants to merge 2 commits into
shopware:nextfrom
bdgraue:fix/docker-in-container-execution
Open

fix(project): support running shopware-cli inside the docker dev container#1100
bdgraue (bdgraue) wants to merge 2 commits into
shopware:nextfrom
bdgraue:fix/docker-in-container-execution

Conversation

@bdgraue

Copy link
Copy Markdown

Follow-up to #1097, which made project create --docker / project dev work for any host UID by running the containers as the calling user. This PR covers the remaining case: running shopware-cli itself inside the dev container (directly, via an alias such as docker compose exec web shopware-cli ..., or when the CLI is shipped in the ghcr.io/shopware/docker-dev image).

Problem

Two issues surface when the CLI runs inside the container:

  1. No docker to exec into. The docker-dev image ships no docker CLI, but a type: docker environment unconditionally builds a DockerExecutor. The first executor command (project storefront-build runs feature:dump) then fails with docker: not found — before any build step.
  2. Unwritable HOME. Inside the container the CLI runs as the mapped host UID, which has no passwd entry, so HOME resolves to /. npm (~/.npm) and composer (~/.composer) then fail with EACCES (e.g. mkdir /.npm).

Changes

  • internal/executor/factory.go — a type: docker environment falls back to local execution when running inside a container that has no docker CLI (detected via /.dockerenv / /run/.containerenv + docker not on PATH). The container is the target environment, so commands run locally. A host without docker keeps the DockerExecutor, so it still fails with a clear error instead of silently running on the host; a container with docker (dind) is unaffected.
  • internal/system/home_linux.go + cmd/root.go — at startup, when HOME is unset or not writable, it is redirected to a writable temp dir, so every child process (the executor's npm/composer/console and the verifier's direct npm/node calls, which all inherit the process env) can write its caches. The writability check uses access(2) (no probe file is written, so shell completion stays side-effect free). Linux only; a no-op when HOME is already writable, so normal host and macOS/Windows usage is unchanged.

Resulting behaviour

Environment type docker present inside container Executor HOME
Host, native local no Local host, no-op
Host + Docker docker yes no Docker (exec, HOME=/tmp from #1097) unchanged
Dev container docker no yes Local (new) redirected (new)
Container + dind docker yes yes Docker (exec) unchanged
macOS / Windows docker yes no Docker no-op

Testing

  • New unit tests: executor fallback (local when forced, docker otherwise) and EnsureWritableHome (keeps a writable HOME, redirects when unset/unwritable).
  • gofmt, go vet, go build (linux/windows/darwin), golangci-lint run ./... and go test ./... all pass.
  • Verified end-to-end in the real ghcr.io/shopware/docker-dev image as UID 1001: the CLI resolves to local execution (exec: php bin/console ..., no docker: not found), redirects HOME to /tmp, and a real npm install succeeds.

Refs #1096

🤖 Generated with Claude Code

Marc Cheng and others added 2 commits June 15, 2026 14:54
… inside a container

When shopware-cli itself runs inside a container (e.g. the docker-dev image,
which ships the CLI but no docker binary), a type:docker environment cannot
`docker compose exec` into anything: the first executor command fails with
"docker: not found". Detect this case (container marker present, docker CLI
absent) and fall back to local execution, since the container is itself the
target environment. A host without docker keeps the DockerExecutor so it still
fails with a clear error instead of silently running on the host.

Refs shopware#1096

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Inside a container shopware-cli runs as the mapped host UID, which has no
passwd entry, so HOME resolves to / and child tools fail with EACCES (npm cache
/.npm, composer ~/.composer). Redirect HOME to a writable temp dir once at
startup when it is unset or not writable, so every child process (executor npm/
composer/console and the verifier's direct npm/node calls) inherits it. Linux
only; a no-op when HOME is already writable, so normal host usage is unchanged.

Refs shopware#1096

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@shyim

Copy link
Copy Markdown
Member

Could you provide maybe an example shopware project or give access to an private one. I would like to further understand the setup 👀

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.

2 participants