dwyl/learn-devops

Diagnosing Failure to Deploy Dokku App to Digital Ocean Instance

nelsonic opened this issue ยท 4 comments

The 2GB DigitalOcean VM ("droplet") we are using is running out of memory (RAM) ... ๐Ÿ˜ž
When I run the free command on the instance we see:
image

Which is bonkers considering we are only running 3 "hello world" style apps on it! (or so I thought...!)

When I run docker ps I see that there are actually 40 Apps running!!
image
short-hand to count apps: docker ps -q $1 | wc -l via: https://gist.github.com/ggtools/af819efc6b8e3287616c

Most of these Docker containers are "test" apps I created using dokku apps:create <appname> while testing my deployment script(s) ... once I confirmed the app (deployment) was working I would "destroy" the app with the command dokku apps:destroy <appname>
thinking that the underlying Docker container would be destroyed also. But, as it turns out the container is still running!!

So, we need a way of clearing out all the "old" docker containers we no longer need in order to free up the memory on the instance for the Apps we do want to be running!

Using @JeffBelback's docker-destroy-all.sh script:
https://gist.github.com/JeffBelback/5687bb02f3618965ca8f

#!/bin/bash
# Stop all containers
docker stop $(docker ps -a -q)
# Delete all containers
docker rm $(docker ps -a -q)
# Delete all images
docker rmi $(docker images -q)

I saved this file to our bin folder on localhost and then ran:

ssh root@138.68.163.126 'bash -s' < ./bin/docker-destroy-all.sh

The output is:
image

i.e. Docker deleting the containers ...

When I run free again:
image
We are back to having a decent amount of memory (RAM) again.

And when I run:

dokku ps:report

I see:
image

Which is expected because none of the Apps are "running" (because their containers were "Nuked!")

Addressing this error first: #26

I'm going to need to write a "Docker Container Cleanup" script to purge all the "old" containers that are no longer being used. The pattern looks like containers that do not have a / in the name property are the ones we want to keep ... I might need to resort to a more "powerful" scripting language than BASH ... ๐Ÿค”

All the apps I am currently deploying to Dokku are deploying without any issues.
The reason that deployment was failing, is that Dokku was attempting to restart nginx but it was using an incorrect command. we "fixed" that in #26 and now deployment works as expected.