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
Codercord
Codercord11mo ago
<#1197976271318171798>
Category
Help needed
Product
Coder OSS (v2)
Platform
Linux
Logs
Please post any relevant logs/error messages.
Phorcys
Phorcys11mo ago
hey, may I ask what the use-case is ?
bamhm182 (BytePen)
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.
gammazeta
gammazetaOP11mo ago
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
Atif
Atif11mo ago
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
gammazeta
gammazetaOP11mo ago
ok , i will research more about terraform
乃ㄖㄒ
乃ㄖㄒ10mo ago
@gammazeta hey 👋, did you find some workarounds for this usecase?
bamhm182 (BytePen)
You can just remove the count attribute from the docker containers.
乃ㄖㄒ
乃ㄖㄒ10mo ago
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?
bamhm182 (BytePen)
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.
lapnd
lapnd10mo ago
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
Phorcys
Phorcys10mo ago
that seems a bit brutal
lapnd
lapnd10mo ago
Yes it is just a tricky/workaround. Can not be used as good solution
ÙwÚ
ÙwÚ10mo ago
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.
Want results from more Discord servers?
Add your server