Open 7d4b9 opened 1 year ago
Thanks for sharing this @7d4b9! As it sounds like this could be an update to documentation, we welcome any contributions to https://containers.dev/ - you can open a PR in its backing repo: https://github.com/devcontainers/devcontainers.github.io.
Hello,
I find that in some case you may prefer to persist your build caches, bash history, etc... inside a local folder instead of inside a volume.
The following approach keeps a subset of cache or history in each project on the local disk.
requirements:
use
onCreateCmd
:Add the following in
.devcontainer/devcontainers.json
:And now create a script
.devcontainer/on-create-cmd.sh
:Do not forget to add execution rights for your script:
Result inside the devcontainer
gitignore
As you can see now the project go build caches, vscode-extensions and bash history are generated inside the project path itself on your local disk.
I recommend that you finally add the following lines to
.devcontainer/.gitignore
to keep those file from versioning:Working example:
You can view a working example of this on one of my personal test project: https://github.com/7d4b9/utrade/tree/dev/.devcontainer
Just open a Codespace container directly on GitHub or checkout the project locally to use your host.
Github Codespace
Keep in mind that here the persistence will occur in the current project checkout host. As it is a VM the data may be lost if this host is changed. However this is changing nothing as it is also the case if the data were kept inside a docker volume if the docker instance is renewed. So this is not a real warn, just an observation :)