cloudyr / googleComputeEngineR

An R interface to the Google Cloud Compute API, for launching virtual machines
https://cloudyr.github.io/googleComputeEngineR/
Other
152 stars 41 forks source link

Restart VMs causes conflict of docker names #30

Closed MarkEdmondson1234 closed 7 years ago

MarkEdmondson1234 commented 7 years ago
/usr/bin/docker: Error response from daemon: Conflict. The name "/rstudio" is already in use by container e043696ddfefec5502deaa1ea0345509f35a378074b1a24cbc25846d7de9d1a9. You have to remove (or rename) that container to be able to reuse that name..

Have to run

docker_cmd(vm, "rm rstudio")
gce_ssh(vm, "sudo systemctl start rstudio.service")

..to restart image or

docker_cmd(vm, "start rstudio")

...to run same container.

jburos commented 7 years ago

Hey - great package! thanks for these great tools.

I ran into this issue & was able to resolve it by adding the following to my systemd service:

ExecStopPost=/usr/bin/docker rm {name-of-image}

This way, the image gets removed after it's stopped, leading to a cleaner restart. It's not perfect, since the start will fail if there's an error on the first start. but it does allow for a clean "restart".

For example (in my case the service & image names are different from yours, but you get the idea):

jburos@test-r-cluster1 ~ $ sudo systemctl start rdockerimg
jburos@test-r-cluster1 ~ $ sudo systemctl status rdockerimg
● rdockerimg.service - rstanarm-simtest-jm
   Loaded: loaded (/etc/systemd/system/rdockerimg.service; static; vendor preset: disabled)
   Active: active (running) since Fri 2017-02-03 22:41:20 UTC; 2s ago
  Process: 2613 ExecStopPost=/usr/bin/docker rm rstanarm-simtest-jm (code=exited, status=0/SUCCESS)
  Process: 2604 ExecStop=/usr/bin/docker stop rstanarm-simtest-jm (code=exited, status=0/SUCCESS)
  Process: 2627 ExecStartPre=/usr/share/google/dockercfg_update.sh (code=exited, status=0/SUCCESS)
 Main PID: 2640 (docker)
   Memory: 4.1M
      CPU: 32ms
   CGroup: /system.slice/rdockerimg.service
           └─2640 /usr/bin/docker run --name=rstanarm-simtest-jm --net=host us.gcr.io/pici-1286/rstanarm-simtest-jm:latest

Feb 03 22:41:21 test-r-cluster1 docker[2640]: [fix-attrs.d] applying owners & permissions fixes...
Feb 03 22:41:21 test-r-cluster1 docker[2640]: [fix-attrs.d] 00-runscripts: applying...
Feb 03 22:41:21 test-r-cluster1 docker[2640]: [fix-attrs.d] 00-runscripts: exited 0.
Feb 03 22:41:21 test-r-cluster1 docker[2640]: [fix-attrs.d] done.
Feb 03 22:41:21 test-r-cluster1 docker[2640]: [cont-init.d] executing container initialization scripts...
Feb 03 22:41:21 test-r-cluster1 docker[2640]: [cont-init.d] conf: executing...
Feb 03 22:41:21 test-r-cluster1 docker[2640]: [cont-init.d] conf: exited 0.
Feb 03 22:41:21 test-r-cluster1 docker[2640]: [cont-init.d] done.
Feb 03 22:41:21 test-r-cluster1 docker[2640]: [services.d] starting services
Feb 03 22:41:21 test-r-cluster1 docker[2640]: [services.d] done.
jburos@test-r-cluster1 ~ $ sudo systemctl restart rdockerimg
jburos@test-r-cluster1 ~ $ sudo systemctl status rdockerimg
● rdockerimg.service - rstanarm-simtest-jm
   Loaded: loaded (/etc/systemd/system/rdockerimg.service; static; vendor preset: disabled)
   Active: active (running) since Fri 2017-02-03 22:41:34 UTC; 49s ago
  Process: 2873 ExecStopPost=/usr/bin/docker rm rstanarm-simtest-jm (code=exited, status=0/SUCCESS)
  Process: 2823 ExecStop=/usr/bin/docker stop rstanarm-simtest-jm (code=exited, status=0/SUCCESS)
  Process: 2884 ExecStartPre=/usr/share/google/dockercfg_update.sh (code=exited, status=0/SUCCESS)
 Main PID: 2898 (docker)
   Memory: 4.2M
      CPU: 32ms
   CGroup: /system.slice/rdockerimg.service
           └─2898 /usr/bin/docker run --name=rstanarm-simtest-jm --net=host us.gcr.io/pici-1286/rstanarm-simtest-jm:latest

Feb 03 22:41:34 test-r-cluster1 docker[2898]: [fix-attrs.d] applying owners & permissions fixes...
Feb 03 22:41:34 test-r-cluster1 docker[2898]: [fix-attrs.d] 00-runscripts: applying...
Feb 03 22:41:34 test-r-cluster1 docker[2898]: [fix-attrs.d] 00-runscripts: exited 0.
Feb 03 22:41:34 test-r-cluster1 docker[2898]: [fix-attrs.d] done.
Feb 03 22:41:34 test-r-cluster1 docker[2898]: [cont-init.d] executing container initialization scripts...
Feb 03 22:41:34 test-r-cluster1 docker[2898]: [cont-init.d] conf: executing...
Feb 03 22:41:34 test-r-cluster1 docker[2898]: [cont-init.d] conf: exited 0.
Feb 03 22:41:34 test-r-cluster1 docker[2898]: [cont-init.d] done.
Feb 03 22:41:34 test-r-cluster1 docker[2898]: [services.d] starting services
Feb 03 22:41:34 test-r-cluster1 docker[2898]: [services.d] done.
MarkEdmondson1234 commented 7 years ago

Great, thanks @jburos !

For reference, anyone can make their own cloudconfig file and launch via gce_vm_template , and in this case modifying this file with @jburos 's solution will fix the issue:

https://github.com/cloudyr/googleComputeEngineR/blob/master/inst/cloudconfig/rstudio.yaml

jburos commented 7 years ago

Yep, that's what I did in this case. Just letting you know since I saw this bug report here. Thanks again for your package

On Sat, Feb 4, 2017 at 3:36 AM Mark notifications@github.com wrote:

Great, thanks @jburos https://github.com/jburos !

For reference, anyone can make their own cloudconfig file and launch via gce_vm_template , and in this case modifying this file with @jburos https://github.com/jburos 's solution will fix the issue:

https://github.com/cloudyr/googleComputeEngineR/blob/master/inst/cloudconfig/rstudio.yaml

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/cloudyr/googleComputeEngineR/issues/30#issuecomment-277428927, or mute the thread https://github.com/notifications/unsubscribe-auth/AA4XPTZLDdbPFmSZtTCy3Xct7n_qzDRbks5rZDiRgaJpZM4K84Uq .

MarkEdmondson1234 commented 7 years ago

Thanks again, yes more for my reference and anyone else who comes across it until fixed :)