Docker Template. Start/stop workspace without delete docker container
Is there any way to stop workspace and keep container
- When create workspace -> create container
- When stop workspace -> stop container
- When start workspace -> restart old container
Can it done with write template or must be custom source coder
14 Replies
<#1197976271318171798>
Category
Help needed
Product
Coder OSS (v2)
Platform
Linux
Logs
Please post any relevant logs/error messages.
hey, may I ask what the use-case is ?
The starting/stopping is done with the count attribute inside of resources. Stop sets the count to 0, and start sets the count to 1. As such, there is no way to keep the container and also have it stop the container when you click stop.
It sounds like you have some data you don't want to lose inside of the container. For that, I would recommend creating volumes and mapping those to the containers. Those volumes can be persisted, and the container will re-mount them when the container is created again.
Thank you @bamhm182 (BytePen) i have try what you say.
But some point for keep container live without delete @Phorcys
- i want workspace like personal computer and personal computer shouldn't reset anything each time restart
- keep state and package have install in start script and when start it will reinstall again . but it hard to do that
- mount folder home/user to volume docker some software have save data and config outside that will be loss
- mount all container to volumes will keep everything but it not good optimize like only stop and restart container without delete and recreate (some script run when recreate workspace in template will conflict with old data)
So all my opinion like workspace is home computer for normal user use and eassy to use
Compare two method
delete container and recreate : good for clean and storage but slow to start, hard to keep state, take more ram when start/stop
stop container and restart: eassy keep state, fast start, take less ram when start/stop but take more storage to keep
But i think get more storage is eassy than, i just need buy more disk . Ram and time of user is important than
As far as I know its a limitation of the docker terraform provider. It cannot restart old containers. Check their GitHub repo or docs about this
ok , i will research more about terraform
@gammazeta hey 👋, did you find some workarounds for this usecase?
You can just remove the count attribute from the docker containers.
Will it be able to update workspaces with new version of templates?
Also, one unrelated question, is there some way to restart docker container from the dashboard without destroying it?
Yes. There's an update button when there's a new template.
No, restarts destroy the container. You can preserve data in volumes, and that data isn't destroyed unless you delete the volume.
If you are using docker containers for workspace (not k8s), one way is create container with restart policy is “always”. Then inside the container/workspace, you can make it crash by terminating/killing the root pid (pid=1) like kill -KILL 1 or kill -TERM 1. Perhaps ovverride reboot app by these comand sothat user just type reboot. Docker engine will take care of restarting crashed container
that seems a bit brutal
Yes it is just a tricky/workaround. Can not be used as good solution
Wouldn't it be better just build your own image (startup script, packages, etc), then use terraform to run your container with that image? You can also mount to keep the files.