Problem 46 · Docker workspace

What happens when you run d2 workspace foobar -c -d and host alias foobar resolves to /tmp/foobar. This default path does not request a rebuild.

START · HOST TERMINAL d2 workspace foobar -c -d 1 Resolve alias on the host foobar → /tmp/foobar · verify it exists · d2 process uses it as cwd The parent terminal's working directory and host alias config are not changed. 2 · CHECK SERVICE STATE Is Compose service workspace running? d2 docker compose ps --status running --services workspace YES · reuse Keep the running container Reuse it; skip start and rebuild. Even -C never rebuilds a running service. NO · start Start the workspace service Default: up -d --no-build workspace With -C: up -d --build workspace (cached). 3 Set container-only alias, then launch workspace Temporary overlay maps foobar → /workspace · host still maps foobar → /tmp/foobar Compose exec runs d2 path add, then d2 workspace foobar -c inside the container. END tmux attached inside container Any step fails → stop

Required setup: the effective Compose config in /tmp/foobar defines service workspace and bind-mounts the project at /workspace. The command does not create that mount. Use -C -d to explicitly request a cached rebuild if stopped.

Command sequence and outcome

Compose commands are launched by the host-side d2 process from /tmp/foobar. Only the commands after compose exec run inside the container.

1 · Resolve the host alias

Host configuration resolves foobar to /tmp/foobar. The d2 process changes its own cwd there so Compose finds the project configuration. This does not change the parent shell directory.

2 · Check whether workspace is running

d2 docker compose ps --status running --services workspace

If it reports workspace, reuse it. A failed probe is an error; startup must not guess.

3 · Start only when it is not running

d2 docker compose up -d --no-build workspace

The explicit --no-build prevents Compose from implicitly building a missing image. To request a cached rebuild of a stopped service, use d2 workspace foobar -d -C; this runs up -d --build workspace and streams build output. A running service is reused even with -C.

4 · Register the alias inside the container

d2 docker compose exec -e DEVELOPER_DASHBOARD_CONFIG_OVERLAY=/dev/shm/developer-dashboard-workspace-config workspace d2 path add foobar /workspace

The overlay is container-side only. Host config remains foobar → /tmp/foobar.

5 · Start or attach to the inner workspace

d2 docker compose exec -it -e DEVELOPER_DASHBOARD_CONFIG_OVERLAY=/dev/shm/developer-dashboard-workspace-config -e TMUX_TMPDIR=/dev/shm workspace d2 workspace foobar -c

Inside the container, the alias resolves to /workspace; d2 creates or attaches to the foobar tmux session.

What you get

Your terminal attaches to tmux running inside the Compose workspace container. With the required bind mount, edits under /workspace are the host files under /tmp/foobar. Detaching returns you to the original host shell directory.

Important: the workspace Compose service must already be configured and must mount the project at /workspace. The outer command runs on the host; only the two compose exec commands run inside the container. The final exec allocates a TTY and explicitly passes TMUX_TMPDIR=/dev/shm, so tmux can attach even when the container's /tmp mount is not writable. The verified checkout was version 5.88; the host-installed d2 is still 5.84 and must be updated before it can use this fix.