Persisting container state across workspace restarts
I am working on setting up development environments with envbuilder, and I would like to emulate the behavior of GitHub Codespaces, where a container is only re-created during a "rebuild" which is distinct from a "restart" in their system. The motivation for this is to persist dotfiles changes that the user may have made.
Is there a way to do this? I've been through https://coder.com/docs/templates/resource-persistence and tried disabling the "count" parameter on the coder_agent terraform resource in the template, but the container is still being re-created.
4 Replies
<#1250179272757477437>
Category
Help needed
Product
Coder OSS (v2)
Platform
Linux
Logs
Please post any relevant logs/error messages.
I've looked at the option called out in https://coder.com/docs/dotfiles#persistent-home but I'm not sure of a good way to mount a volume into the home directory without also nuking all the files there from the container build, some of which are important and would need to be re-created another way.
I ended up working around this by creating a script that replaces home directory files with soft links to a folder that is persistent.
hey @Aaron Taylor
the container will always be recreated because that's how the lifecycle is intended
you don't want to leave dangling containers potentially running heavy tasks and consuming resources for no reason
if you're using docker, you can do a volume mount
a volume mount will grab the already existing files in the docker image on creation, but further edits won't count
the best thing to do is usually to use
/etc/skel
(Linux equivalent of C:\Users\Default
on Windows) which will contain all of the files that should be in your user's home by default.
Every newly created user on a system will have /etc/skel
's contents copied to their home.
in your case, you should write to /etc/skel
first, then create the user
if that's not possible, then something like this also works (and might be useful if you want the default files to always update) :
https://github.com/coder/coder/blob/3d30c8dc6858538378663efc77e8a96cb544d792/examples/templates/docker/main.tf#L32-L36