dwyl / learn-docker

šŸš¢ Learn how to use docker.io containers to consistently deploy your apps on any infrastructure.
230 stars 32 forks source link

Command for restarting all running docker containers when Dokku Deploy is Failing ...? #13

Closed nelsonic closed 6 years ago

nelsonic commented 7 years ago

Deploying to a Dokku (Docker) Container is not working because the previous deploy failed. šŸ˜ž

nelson@local:ruby-rails-sample $ git push dokku
Counting objects: 6, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (5/5), done.
Writing objects: 100% (6/6), 539 bytes | 0 bytes/s, done.
Total 6 (delta 2), reused 0 (delta 0)
-----> Cleaning up...
-----> Building ruby-rails-sample from herokuish...
remote: docker: Error response from daemon: grpc: the connection is unavailable.
To 178.62.95.224:ruby-rails-sample
 ! [remote rejected] master -> master (pre-receive hook declined)
error: failed to push some refs to 'dokku@178.62.95.224:ruby-rails-sample'

Tried to Login to the DigitalOcean VM to attempt to restart:

root@dokku-512mb-lon1-01:~# dokku ps:restart ruby-rails-sample
-----> Releasing ruby-rails-sample (dokku/ruby-rails-sample:latest)...
-----> Deploying ruby-rails-sample (dokku/ruby-rails-sample:latest)...
-----> Attempting to run scripts.dokku.predeploy from app.json (if defined)
-----> App Procfile file found (/home/dokku/ruby-rails-sample/DOKKU_PROCFILE)
-----> DOKKU_SCALE file found (/home/dokku/ruby-rails-sample/DOKKU_SCALE)
=====> web=1
docker: Error response from daemon: grpc: the connection is unavailable.
-----> Attempting pre-flight checks
       For more efficient zero downtime deployments, create a file CHECKS.
       See http://dokku.viewdocs.io/dokku/deployment/zero-downtime-deploys/ for examples
       CHECKS file not found in container: Running simple container check...
-----> Waiting for 10 seconds ...
App container failed to start!!
=====> ruby-rails-sample web container output:
=====> end ruby-rails-sample web container output

I tried deleting the .deploy.lock (in our case located at /home/dokku/ruby-rails-sample.deploy.lock) as per http://stackoverflow.com/questions/21247195/what-is-the-proper-command-to-restart-a-dokku-app-from-ssh

but that didn't work. šŸ˜¢

So I tried resorting to "Nuking" ... i.e. restarting all the docker processes

docker restart $(docker ps -a -q)

but unfortunately, we got this error message:

Error response from daemon: Cannot restart container acc3d7d423f9: grpc: the connection is unavailable
Error response from daemon: Cannot restart container 4ad2f7c83945: grpc: the connection is unavailable
Error response from daemon: Cannot restart container 0912cc9222c6: grpc: the connection is unavailable
Error response from daemon: Cannot restart container a84192f5710b: grpc: the connection is unavailable
Error response from daemon: Cannot restart container b7422015aa65: grpc: the connection is unavailable
Error response from daemon: Cannot restart container 0a6d448523dd: Cannot kill container 0a6d448523dd61784f8eb9b660bcf628df5fe36165050f7ff573e7e602436a07: rpc error: code = 14 desc = grpc: the connection is unavailable
Error response from daemon: Cannot restart container 21540d6d65a9: Cannot kill container 21540d6d65a9f629da82d5774e67d04e6f3d84edb66a2373c307d8611835927a: rpc error: code = 14 desc = grpc: the connection is unavailable
Error response from daemon: Cannot restart container 8f43760c1203: Cannot kill container 8f43760c1203b45d062e5a7eab720a13219cdd7498beaa740b06ea9326b01573: rpc error: code = 14 desc = grpc: the connection is unavailable
nelsonic commented 7 years ago

I decided to "power cycle" (restart) the VM: image

The VM re-start worked. But then when I attempt to start/restart the Dokku app:

dokku ps:restart ruby-rails-sample

Get:

App container failed to start!!
=====> ruby-rails-sample web container output:
       setuidgid: fatal: unable to run bundle: file does not exist
       setuidgid: fatal: unable to run bundle: file does not exist
       setuidgid: fatal: unable to run bundle: file does not exist
       setuidgid: fatal: unable to run bundle: file does not exist
       setuidgid: fatal: unable to run bundle: file does not exist
       setuidgid: fatal: unable to run bundle: file does not exist
       setuidgid: fatal: unable to run bundle: file does not exist
=====> end ruby-rails-sample web container output
nelsonic commented 7 years ago

The Dokku (docker) container is still running. When we visit the sample app in the browser it's up: dokku-ruby-rails-sample-running

So I mannually stopped the app:

dokku ps:stop ruby-rails-sample

And then get an Nginx Gateway Error: image

Which in our case is a good sign because it means the Rails app isn't running! šŸ˜‰ So I pushed the app to DO again:

git push dokku

It worked!! šŸŽ‰

nelsonic commented 7 years ago

Setup a subdomain for the app:

dokku domains:add ruby-rails-sample hits.dwyl.com

Which had the following output:

-----> Added hits.dwyl.com to ruby-rails-sample
-----> Unsetting ruby-rails-sample
-----> Unsetting DOKKU_NGINX_PORT
-----> Unsetting DOKKU_NGINX_SSL_PORT
-----> Unsetting DOKKU_PROXY_PORT_MAP
-----> Setting config vars
       NO_VHOST: 0
-----> Setting config vars
       DOKKU_NGINX_PORT: 80
-----> Setting config vars
       DOKKU_PROXY_PORT_MAP: http:80:5000
-----> Configuring ruby-rails-sample.hits.dwyl.com...(using built-in template)
-----> Creating http nginx.conf
-----> Running nginx-pre-reload
       Reloading nginx

And it worked as expected: image

Don't worry this is not what we are going to display for the "hits" app.

nelsonic commented 6 years ago

dokku ps:restart <app> via: https://stackoverflow.com/questions/21247195/what-is-the-proper-command-to-restart-a-dokku-app-from-ssh