DEV Community

Mahesh
Mahesh

Posted on

Manage vps RAM usage by docker containers

I recently had an issue where I couldn't connect to my VPS server. I thought it was an internet connection issue, but it turned out to be high RAM usage on my server.

I tried to find a monitoring tool to help me figure out what was going on, but the information I found was too lengthy and didn't seem relevant to my specific issue.

In the end, I figured out a quick way to fix the problem myself. Here's what I did:

  1. get list of docker containers according to their RAM/Memory-Usage using docker stats
docker stats --no-stream --format "table {{.Name}}\t{{.MemUsage}}" | sort -k 2 -hr
# --no-steam: by default docker stats is streams information, which sometimes hangs 
#    command line --no-stream ask stats one time instead of streaming
# sort -k 2: sort list considering 2nd column which is MemUsage here
# sort -hr: h represents human-redable number, r represents reverse (descending order)
Enter fullscreen mode Exit fullscreen mode
  1. shut down or delete unnecessory containers using docker stop

And that's it, you can check again the reduced RAM usage on vps server by running htop

Heroku

Build apps, not infrastructure.

Dealing with servers, hardware, and infrastructure can take up your valuable time. Discover the benefits of Heroku, the PaaS of choice for developers since 2007.

Visit Site

Top comments (0)

Image of Docusign

🛠️ Bring your solution into Docusign. Reach over 1.6M customers.

Docusign is now extensible. Overcome challenges with disconnected products and inaccessible data by bringing your solutions into Docusign and publishing to 1.6M customers in the App Center.

Learn more