- Notifications
You must be signed in to change notification settings - Fork924
Can I persist docker container?#7097
-
In my use case, we are not familiar with changing template each time, so I would like to keep the container there when stopping, and restart the container when starting, instead creating a new one. |
BetaWas this translation helpful?Give feedback.
All reactions
Replies: 4 comments 8 replies
-
You should look at mounting volumes to persist your workspace directories. See this template for example. https://github.com/matifali/coder-templates/blob/main/deeplearning/main.tf |
BetaWas this translation helpful?Give feedback.
All reactions
-
I know that the usual way is to mount volumes to persist workspace, and we are using it. but I still want the possibility to keep the container, so that I can use it like an VM, and use the most basic template for everything, although it might cost more storage. |
BetaWas this translation helpful?Give feedback.
All reactions
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
-
Try setting |
BetaWas this translation helpful?Give feedback.
All reactions
-
I tried it right now, but it doesn't seem to work. When I stop the workspace, the container doesn't stop at all, and I can still connect to it. When I restart the workspace, the container is still recreated. (My test file under root disapperred, and the container ID changed.) |
BetaWas this translation helpful?Give feedback.
All reactions
-
I added BUT, if I don't stop the container after stopping the workspace, and start the workspace, wired things happen, unable to connect (the ui keeps loading, Probably, coder should stop all container when stopping a workspace? By the way, I see nothing related to stopping a container interraform docs. Probably terraform simply doesn't support stopping a container? Can anyone tell me is that correct? |
BetaWas this translation helpful?Give feedback.
All reactions
👀 1
-
I am not sure, but there are some options relating to stopping a container here,https://registry.terraform.io/providers/kreuzwerker/docker/latest/docs/resources/container |
BetaWas this translation helpful?Give feedback.
All reactions
-
I got a feeling that the stop in the doc is only used for (before) destroy. |
BetaWas this translation helpful?Give feedback.
All reactions
👀 1
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
-
https://discuss.hashicorp.com/t/docker-provider-restart-stopped-containers-instead-of-recreating/7365 |
BetaWas this translation helpful?Give feedback.
All reactions
-
Thanks. Probably this is the case. |
BetaWas this translation helpful?Give feedback.
All reactions
-
You cannot persist a container on workspace stop. Even if you somehow prevent terraform from destroying it it will be recreated/replaced on the next workspace restart. |
BetaWas this translation helpful?Give feedback.
All reactions
-
I hit this same issue as well. Let me provide a little more usecase info to justify the need. We are using the Docker Container template w/a-few tweeks. We like that, it's fast! As opposed to DevContainer (EnvBuilder). We have a case where we use a mostly complete image, but we want to add some addtl things (like vscode extensions and a few other things). Here's the work-around that might-be-awful or might-not-be (we'll see I guess) add this to the bottom of your Container template
now, you must also change the count variable on your "workspace" resource
The full life cycle as tested is this...
I fear what happens if a stop doesn't actually stop? Maybe that's not a thing, but does seem like there is some potential for state inversion sync problem. We'll see I guess. |
BetaWas this translation helpful?Give feedback.
All reactions
-
Hi there. I tried your method and found it does not work. In the full life cycle you tested, the step 1 and 2 worked as expected. However, the step 3, the Coder seems to receate the workspace and then execute null_resource. This leads to the recreation of the container, and thus the data is destroied. |
BetaWas this translation helpful?Give feedback.