How to Persist Claude CLI Session Login Across Docker Container Rebuilds
Developers using Claude Code in Docker containers face a recurring login issue because the session file ~/.claude.json is not stored in a persistent volume, causing it to be wiped on every container rebuild. Since Docker named volumes back a directory rather than a single file, mounting a volume directly onto a file path fails. The workaround involves creating a dedicated directory, placing the session file inside it, and symlinking it back to the expected ~/.claude.json path in the home directory. A docker-compose volume is then mapped to that directory, and ownership is fixed via a post-install script to ensure the container user retains access. One caveat to watch for is atomic write behavior in apps, where a write-then-rename operation can silently replace the symlink with a plain file, breaking persistence without any error.
This is an AI-generated summary. ShortSingh links to the original source for the complete article.
Discussion (0)
Log in to join the discussion and vote.
Log in