Skip to content

Persist state and local keys across devcontainer rebuilds in VSCode #40

Closed
@maxlyth

Description

@maxlyth

This devcontainer feature stores the Tailscale state in /workspaces/.tailscale/ but that is outside the structure that is automatically mapped by VSCode to the local project directory so the state was lost each time the container is rebuilt.

I have a few other states that I need to persist across container rebuilds such as shell history and authkeys for CLI tools such as Supabase and Doppler. My solution is to bind mount these to a .devcontainer/volumes/ folder.

You can also use Docker Volumes but these are opaque, easy to loose, and I prefer to keep all config relating to a project together. You probably want to add the volumes directory to .gitignore as there are likely privileged keys stored in there and each project contributor keeps their own separate keys.

To setup, once Tailscale is connected, inside the devcontainer run:
mkdir .devcontainer/volumes && sudo cp -r /workspaces/.tailscale .devcontainer/volumes

and then add the following to the mounts section of devcontainer.json
"source=${localWorkspaceFolder}/.devcontainer/volumes/.tailscale,target=/workspaces/.tailscale,type=bind"

If someone knows a better way to do this then please chime in.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions