Skip to content

feat: keep shell and database client history in per-container volumes, for #8895 - #8947

Closed
rfay wants to merge 2 commits into
ddev:mainfrom
rfay:20261014_rfay_history_volumes
Closed

rfay wants to merge 2 commits into
ddev:mainfrom
rfay:20261014_rfay_history_volumes

Conversation

@rfay

@rfay rfay commented Oct 14, 2026

Copy link
Copy Markdown
Member

Short Summary (TL;DR)

The web and db containers now keep their Bash, MySQL and psql history in their own volumes, ddev-<project>-web-history and ddev-<project>-db-history, mounted at /mnt/ddev-history, instead of in the shared ddev-global-cache volume. On first start, existing history is copied over from ddev-global-cache.

The Issue

History is per-container state, but it lived in ddev-global-cache, a volume that every project's web and db containers mount read-write. Giving each container its own volume leaves each with a single writer, as providers like Apple container require, and moves one more thing out of the shared volume.

How This PR Solves The Issue

DDEV creates the history volumes along with the project's other volumes, and the existing pre-start chown container gives them the container user's ownership. A history volume created by that start is first seeded from bashhistory/<project>-<service> and mysqlhistory/<project>-<service> in ddev-global-cache. ddev delete removes both volumes.

The db container gets HISTFILE from compose, so its Bash history now survives a restart without a db image change. Both containers get PSQL_HISTORY, so psql history is kept too. The web image's bash.bashrc points HISTFILE at the new volume.

The db entrypoint still creates the old history directories; that goes away with the next db image change.

Manual Testing Instructions

ddev utility download-ddev --pr 8947
export PATH="$HOME/tmp/ddev-download-ddev/pr-8947:$PATH"
docker run --rm -v ddev-global-cache:/m busybox sh -c 'for s in web db; do mkdir -p /m/bashhistory/histtest-$s; echo old-bash-$s > /m/bashhistory/histtest-$s/bash_history; done'
mkdir -p ~/tmp/histtest && cd ~/tmp/histtest
ddev config --project-type=php && ddev start
# Expect old-bash-web and old-bash-db, files owned by your uid
docker run --rm -v ddev-histtest-web-history:/h busybox sh -c 'ls -ln /h; cat /h/bash_history'
docker run --rm -v ddev-histtest-db-history:/h busybox cat /h/bash_history
ddev ssh -s db    # run any command, then exit
ddev restart
ddev exec -s db cat /mnt/ddev-history/bash_history
# Expect the command you ran
ddev delete -Oy
docker volume ls | grep histtest
# Expect no volumes

Automated Testing Overview

TestProcessHooks now expects the new MYSQL_HISTFILE path in the db container.

Release/Deployment Notes

The web image changes. Clearing ddev-global-cache no longer removes history; ddev delete does.

🤖 Developed with assistance from Claude Code

Co-Authored-By: Claude Opus 5.5 [email protected]

@rfay
rfay requested review from a team as code owners October 14, 2026 17:44
@github-actions github-actions Bot added dependencies Pull requests that update a dependency file enhancement labels Oct 14, 2026
@github-actions

github-actions Bot commented Oct 14, 2026 •

Copy link
Copy Markdown

Download this PR's build for your OS and architecture with:

ddev utility download-ddev --pr 8947

Or download the artifact for your OS and architecture directly:

See Testing a PR.

Open in GitHub Codespaces

@github-actions

Copy link
Copy Markdown

Pushed updated container image(s) for this PR:

  • ddev/ddev-webserver-prod:85bef53b7f
  • ddev/ddev-webserver:85bef53b7f

@stasadev

Copy link
Copy Markdown
Member

Instead of a new volume for each container, could the history live on the host, in the project's .ddev? For example, .ddev/.history/web and .ddev/.history/db bind-mounted at /mnt/ddev-history. A whole volume seems like a lot for a few small text files.

That removes most of the Go changes. There's nothing to create, seed, chown, or remove on ddev delete, just an os.MkdirAll before start (so that Docker doesn't create the directory as root) and one mount line per service. Apple container's single-writer limit applies to named volumes, not bind mounts. History would also survive docker system prune --volumes and switching Docker providers.

What it needs:

  • .history in the generated .ddev/.gitignore, because Bash history can contain passwords and tokens. Projects that took over their .ddev/.gitignore won't get the entry.
  • A separate read-write mount for web, because web mounts .ddev read-only.
  • Nothing for no_bind_mounts: there's no host directory there, and not keeping history in that mode seems fine.
  • The migration from ddev-global-cache could be dropped. Losing shell history once on upgrade doesn't matter much.

The HISTFILE for db and PSQL_HISTORY changes make sense either way.

🤖 Developed with assistance from Claude Code

@rfay
rfay force-pushed the 20261014_rfay_history_volumes branch from 04224ad to 8270040 Compare October 17, 2026 23:28
@rfay

rfay commented Oct 17, 2026 •

Copy link
Copy Markdown
Member Author

Your exact suggestion works OK, with the trade-off about no-bind-mounts not having history, which is OK.

The problem I worry about is that some docker providers will mount on the host with the user-id of the in-container user, which can accidentally be root in some cases, especially including the situation of an empty directory in the container causing creation on the host. We definitely don't want root or non-user directories or files created on the host.

It's fairly likely we could prevent this situation by making sure to pre-create directories and files on the host.

I'll try implementing a safe version of your proposal so we can look at it.

Edit:

@rfay
rfay requested a review from stasadev October 18, 2026 14:04
rfay added a commit that referenced this pull request Oct 21, 2026
… for #8895

Each service now keeps its shell and database client history in `.ddev/.history/<service>` on the host, bind-mounted at `/mnt/ddev-history`, instead of in the shared `ddev-global-cache` volume. This is an alternative to #8947, which uses a volume per container, following @stasadev's suggestion there.

- For #8895

History lived in `ddev-global-cache`, which every project's containers mount read-write, so it doesn't fit providers like Apple container that need a single writer per volume. A bind mount avoids that limit, but it can leave root-owned files in the project that the user can't remove without sudo, which has to be prevented without any escalation on the host.

DDEV creates `.ddev/.history/<service>` as the host user before `compose up`, with a `.gitignore` of `*` so history never reaches git, and mounts it with `create_host_path: false` so Docker can't create it as root. The mount goes only into services that run as the uid the host user maps to: the host uid on rootful Docker and Podman with `keep-id`, `0` on rootless Docker, and any uid on providers that map ownership. That covers `web`, `db`, and custom services running as `${DDEV_UID}`, which get `HISTFILE`, `MYSQL_HISTFILE`, `PSQL_HISTORY`, `REDISCLI_HISTFILE`, `SQLITE_HISTORY`, `NODE_REPL_HISTORY` and `PYTHON_HISTORY`. `x-ddev.omit-history: true` leaves a service out.

In the web image, a shell running as another uid, like a root shell, keeps its history in the container instead. Anything root writes anyway is given back to the host user on Linux by the existing chown container on `ddev start`, and by a chown container on `ddev delete`, both through Docker so no sudo is needed. Nothing is kept with `no_bind_mounts`.

The db image is unchanged, so a root shell in `db` still writes to the mount until its next image change; the chown on start and delete covers it.

On Linux with rootful Docker:

```bash
ddev utility download-ddev --pr 8964
export PATH="$HOME/tmp/ddev-download-ddev/pr-8964:$PATH"
mkdir -p ~/tmp/histtest && cd ~/tmp/histtest
ddev config --project-type=php && ddev start
ls -la .ddev/.history          # .gitignore, web, db, all owned by you
ddev exec -u root "bash -ic 'echo \$HISTFILE'"   # /root/.bash_history
ddev exec "bash -ic 'echo \$HISTFILE'"           # /mnt/ddev-history/bash_history
ddev exec -u root 'mkdir /mnt/ddev-history/rootdir && touch /mnt/ddev-history/rootdir/f'
rm -rf .ddev/.history/web/rootdir   # Permission denied
ddev restart
rm -rf .ddev/.history/web/rootdir   # succeeds
ddev delete -Oy && rm -rf .ddev/.history   # succeeds without sudo
```

See the [Shell and Client History](https://ddev--8964.org.readthedocs.build/en/8964/users/usage/architecture/#shell-and-client-history) docs.

`TestHistoryBindMount` checks the history environment in `web` and `db`, that a write lands in `.ddev/.history/web`, and that a root-owned directory is removable by the host user after a restart. `TestProcessHooks` expects the new `MYSQL_HISTFILE` path.

The web image changes. Existing history in `ddev-global-cache` isn't migrated, so users start with empty history once. Mutagen ignores `/.ddev/.history`, which changes the generated `mutagen.yml` and recreates the sync session on the next start.

🤖 Developed with assistance from [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude Opus 5.5 <[email protected]>
rfay and others added 2 commits October 20, 2026 21:05
…, for ddev#8895

The web and db containers now keep their Bash, MySQL and `psql` history in their own volumes, `ddev-<project>-web-history` and `ddev-<project>-db-history`, mounted at `/mnt/ddev-history`, instead of in the shared `ddev-global-cache` volume. On first start, existing history is copied over from `ddev-global-cache`.

- For ddev#8895

History is per-container state, but it lived in `ddev-global-cache`, a volume that every project's web and db containers mount read-write. Giving each container its own volume leaves each with a single writer, as providers like Apple container require, and moves one more thing out of the shared volume.

DDEV creates the history volumes along with the project's other volumes, and the existing pre-start chown container gives them the container user's ownership. A history volume created by that start is first seeded from `bashhistory/<project>-<service>` and `mysqlhistory/<project>-<service>` in `ddev-global-cache`. `ddev delete` removes both volumes.

The db container gets `HISTFILE` from compose, so its Bash history now survives a restart without a db image change. Both containers get `PSQL_HISTORY`, so `psql` history is kept too. The web image's `bash.bashrc` points `HISTFILE` at the new volume.

The db entrypoint still creates the old history directories; that goes away with the next db image change.

```bash
ddev utility download-ddev --pr 8947
export PATH="$HOME/tmp/ddev-download-ddev/pr-8947:$PATH"
docker run --rm -v ddev-global-cache:/m busybox sh -c 'for s in web db; do mkdir -p /m/bashhistory/histtest-$s; echo old-bash-$s > /m/bashhistory/histtest-$s/bash_history; done'
mkdir -p ~/tmp/histtest && cd ~/tmp/histtest
ddev config --project-type=php && ddev start
docker run --rm -v ddev-histtest-web-history:/h busybox sh -c 'ls -ln /h; cat /h/bash_history'
docker run --rm -v ddev-histtest-db-history:/h busybox cat /h/bash_history
ddev ssh -s db    # run any command, then exit
ddev restart
ddev exec -s db cat /mnt/ddev-history/bash_history
ddev delete -Oy
docker volume ls | grep histtest
```

`TestProcessHooks` now expects the new `MYSQL_HISTFILE` path in the db container.

The web image changes. Clearing `ddev-global-cache` no longer removes history; `ddev delete` does.

🤖 Developed with assistance from [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@rfay
rfay force-pushed the 20261014_rfay_history_volumes branch from 8270040 to ed20156 Compare October 21, 2026 03:07
@github-actions

Copy link
Copy Markdown

Pushed updated container image(s) for this PR:

  • ddev/ddev-webserver-prod:e6a2ba6c9e
  • ddev/ddev-webserver:e6a2ba6c9e

rfay added a commit that referenced this pull request Oct 22, 2026
… for #8895

Each service now keeps its shell and database client history in `.ddev/.history/<service>` on the host, bind-mounted at `/mnt/ddev-history`, instead of in the shared `ddev-global-cache` volume. This is an alternative to #8947, which uses a volume per container, following @stasadev's suggestion there.

- For #8895

History lived in `ddev-global-cache`, which every project's containers mount read-write, so it doesn't fit providers like Apple container that need a single writer per volume. A bind mount avoids that limit, but it can leave root-owned files in the project that the user can't remove without sudo, which has to be prevented without any escalation on the host.

DDEV creates `.ddev/.history/<service>` as the host user before `compose up`, with a `.gitignore` of `*` so history never reaches git, and mounts it with `create_host_path: false` so Docker can't create it as root. The mount goes only into services that run as the uid the host user maps to: the host uid on rootful Docker and Podman with `keep-id`, `0` on rootless Docker, and any uid on providers that map ownership. That covers `web`, `db`, and custom services running as `${DDEV_UID}`, which get `HISTFILE`, `MYSQL_HISTFILE`, `PSQL_HISTORY`, `REDISCLI_HISTFILE`, `SQLITE_HISTORY`, `NODE_REPL_HISTORY` and `PYTHON_HISTORY`. `x-ddev.omit-history: true` leaves a service out.

In the web image, a shell running as another uid, like a root shell, keeps its history in the container instead. Anything root writes anyway is given back to the host user on Linux by the existing chown container on `ddev start`, and by a chown container on `ddev delete`, both through Docker so no sudo is needed. Nothing is kept with `no_bind_mounts`.

The db image is unchanged, so a root shell in `db` still writes to the mount until its next image change; the chown on start and delete covers it.

On Linux with rootful Docker:

```bash
ddev utility download-ddev --pr 8964
export PATH="$HOME/tmp/ddev-download-ddev/pr-8964:$PATH"
mkdir -p ~/tmp/histtest && cd ~/tmp/histtest
ddev config --project-type=php && ddev start
ls -la .ddev/.history          # .gitignore, web, db, all owned by you
ddev exec -u root "bash -ic 'echo \$HISTFILE'"   # /root/.bash_history
ddev exec "bash -ic 'echo \$HISTFILE'"           # /mnt/ddev-history/bash_history
ddev exec -u root 'mkdir /mnt/ddev-history/rootdir && touch /mnt/ddev-history/rootdir/f'
rm -rf .ddev/.history/web/rootdir   # Permission denied
ddev restart
rm -rf .ddev/.history/web/rootdir   # succeeds
ddev delete -Oy && rm -rf .ddev/.history   # succeeds without sudo
```

See the [Shell and Client History](https://ddev--8964.org.readthedocs.build/en/8964/users/usage/architecture/#shell-and-client-history) docs.

`TestHistoryBindMount` checks the history environment in `web` and `db`, that a write lands in `.ddev/.history/web`, and that a root-owned directory is removable by the host user after a restart. `TestProcessHooks` expects the new `MYSQL_HISTFILE` path.

The web image changes. Existing history in `ddev-global-cache` isn't migrated, so users start with empty history once. Mutagen ignores `/.ddev/.history`, which changes the generated `mutagen.yml` and recreates the sync session on the next start.

🤖 Developed with assistance from [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@rfay

rfay commented Oct 27, 2026

Copy link
Copy Markdown
Member Author

Comment by Claude Code, at @rfay's request.

Closing in favor of a broader approach agreed on in #8895: each project gets its own cache volumes, <project>-web-cache and <project>-db-cache, mounted at /mnt/ddev-project-cache. Shell and client history moves there, and so do the composer, npm, yarn, corepack, pip, and terminus caches and n_prefix, because sharing those across projects has caused several accidental problems, including Pantheon auth leaking between projects through the terminus cache.

What carries over from this PR: setting HISTFILE, MYSQL_HISTFILE, and PSQL_HISTORY in the compose template, giving db a real HISTFILE, removing the volumes with ddev delete, and seeding history from ddev-global-cache when the volume is first created. Since the volume now holds the package caches too, it's no longer a whole volume for a few text files.

@rfay rfay closed this Oct 27, 2026
rfay added a commit to rfay/ddev that referenced this pull request Oct 28, 2026
Each project now gets `<project>-web-cache` and `<project>-db-cache` volumes, mounted at `/mnt/ddev-project-cache`. Shell history and the package caches move there from `ddev-global-cache`, and DDEV no longer chowns the shared volume.

- For ddev#8895

Sharing caches across projects caused accidental problems. For example, the terminus cache carried one project's Pantheon login into other projects. Every project start also ran `chown -R` on the whole shared volume, so two users or user namespaces fought over its ownership.

- The web volume holds `history/`, `composer`, `npm`, `yarn`, `corepack`, `pip`, `terminus/cache`, and `n_prefix`. The db volume holds `history/` and a copy of the db global commands.
- db no longer mounts `ddev-global-cache`. Start copies `global-commands/db` into the db volume, and `ddev mysql`, `ddev psql`, and other db global commands run from there.
- Start sets `ddev-global-cache` to mode 1777 and never chowns it. It chowns only the project volumes.
- When a cache volume is first created, start copies the old bash and MySQL history into it. Caches start cold.
- `ddev delete` removes both volumes.
- Web still mounts `ddev-global-cache` at the same path, so add-ons that use it keep working.

This replaces ddev#8947 and ddev#8964, which moved only history.

```bash
ddev utility download-ddev --pr 9024
export PATH="$HOME/tmp/ddev-download-ddev/pr-9024:$PATH"
ddev config --project-type=drupal11 --docroot=web
ddev start
docker volume ls | grep -- -cache
ddev exec 'echo $COMPOSER_CACHE_DIR $npm_config_cache'
ddev mysql -e 'select 1'
ddev exec -s db 'grep ddev-global-cache /proc/mounts || echo none'
ddev delete -Oy
docker volume ls | grep -- -cache
```

Changed docs: https://ddev--9024.org.readthedocs.build/en/9024/users/usage/architecture/#project-cache-volumes

`TestProjectCacheVolumes` checks the volumes, the env paths, history migration and persistence, the db global commands, and the removal by `ddev delete`.

The first Composer or npm install in each project downloads everything again. Old caches stay in `ddev-global-cache` until the user removes that volume.

🤖 Developed with assistance from [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude Opus 5.5 <[email protected]>
rfay added a commit to rfay/ddev that referenced this pull request Oct 28, 2026
Each project now gets `<project>-web-cache` and `<project>-db-cache` volumes, mounted at `/mnt/ddev-project-cache`. Shell history and the package caches move there from `ddev-global-cache`, and DDEV no longer chowns the shared volume.

- For ddev#8895

Sharing caches across projects caused accidental problems. For example, the terminus cache carried one project's Pantheon login into other projects. Every project start also ran `chown -R` on the whole shared volume, so two users or user namespaces fought over its ownership.

- The web volume holds `history/`, `composer`, `npm`, `yarn`, `corepack`, `pip`, `terminus/cache`, and `n_prefix`. The db volume holds `history/` and a copy of the db global commands.
- db no longer mounts `ddev-global-cache`. Start copies `global-commands/db` into the db volume, and `ddev mysql`, `ddev psql`, and other db global commands run from there.
- Start sets `ddev-global-cache` to mode 1777 and never chowns it. It chowns only the project volumes.
- When a cache volume is first created, start copies the old bash and MySQL history into it. Caches start cold.
- `ddev delete` removes both volumes.
- Web still mounts `ddev-global-cache` at the same path, so add-ons that use it keep working.

This replaces ddev#8947 and ddev#8964, which moved only history.

```bash
ddev utility download-ddev --pr 9024
export PATH="$HOME/tmp/ddev-download-ddev/pr-9024:$PATH"
ddev config --project-type=drupal11 --docroot=web
ddev start
docker volume ls | grep -- -cache
ddev exec 'echo $COMPOSER_CACHE_DIR $npm_config_cache'
ddev mysql -e 'select 1'
ddev exec -s db 'grep ddev-global-cache /proc/mounts || echo none'
ddev delete -Oy
docker volume ls | grep -- -cache
```

Changed docs: https://ddev--9024.org.readthedocs.build/en/9024/users/usage/architecture/#project-cache-volumes

`TestProjectCacheVolumes` checks the volumes, the env paths, history migration and persistence, the db global commands, and the removal by `ddev delete`.

The first Composer or npm install in each project downloads everything again. Old caches stay in `ddev-global-cache` until the user removes that volume.

🤖 Developed with assistance from [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

dependencies Pull requests that update a dependency file enhancement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants