If Docker is your container service of choice, you know how easy it is to create and deploy containers. Chances are you've already done so and have numerous containers running on your network. However, do you know how well those containers are performing? If you're familiar with Linux, you might wish there were an top/htop app geared specifically for containers.
That's right, one of the best means of monitoring your containers is an open source tool, found on Github, called ctop. With this app, you can get a quick overview of your containers, their names, IDs, and how much CPU, Memory, and Network Rx/Tx data. Ctop even allows you to filter what you're viewing, and gives you an expanded view of a selected container. Although it may not offer a massive amount of features, it does the job and does it well. The tool is easy to install, and even easier to use. I'll demonstrate on a Ubuntu 16.04 platform, but ctop can be installed on nearly any Linux distribution.
There are two ways to install ctop: As an app or a container. I'll show you both. First, we'll install ctop as a container. To do this, log into your container server and issue the following command to deploy the container:
docker run -ti -v /var/run/docker.sock:/var/run/docker.sock quay.io/vektorlab/ctop:latest
The above command will pull down the necessary image, deploy the container, and drop you into the app. To exit ctop, hit [Ctl]+[x]. The problem with using ctop in this manner is that you must issue the above command every time you wish to run ctop. That's too much typing. Let's make it easier.
We can install ctop as a local application. To do so, we'll pull down the executable from Github, move it into /usr/local/bin, and give it the necessary permissions with the following commands:
wget https://github.com/bcicen/ctop/releases/download/v0.4.1/ctop-0.4.1-linux-amd64 -O ctop sudo mv ctop /usr/local/bin/ sudo chmod +x /usr/local/bin/ctop
At this point, you can start up ctop anytime with the command ctop.
Using ctop is simple. Once you have the tool open (Figure A), you'll see all of your currently active containers listed.
As you can see, one of my containers (wonderful_stallman) is using 1.37GB of memory. That particular container is an instance of Only Office, so it makes sense it would be using a larger amount of resources. However, it's nearly hogging up all of the system resources on my virtual machine, so I might want to consider migrating that container to a beefier virtual machine.
With ctop, you can easily filter your containers. Say you have a large number of containers on your server and want to check on the resource usage of a particular deployment. With ctop open, hit the f key on your keyboard to open the filter (Figure B).
Type the name of a container and ctop will display only the results that match the filter. This is incredibly helpful when your Docker server hosts numerous containers. To clear a filter, type f again, and then hit Enter on the keyboard.
If you select a container from the listing and hit Enter, you will see a bit more information laid out in easy to read graphs (Figure C).
To exit out of the expanded view, type q. To exit out of ctop, type q, and you'll be returned to your bash prompt.
Just enough info
And that's pretty much the gist of using ctop on Linux for viewing details of your containers. This tool doesn't offer extensive information, but it will give you just enough information to keep you aware of how your containers are performing. Ctop could easily be a first line of defense in troubleshooting Docker containers.
- How to get quick stats on your Docker containers (TechRepublic)
- How to run ONLYOFFICE Server as a Docker container (TechRepublic)
- How to share data between a Docker container and host (TechRepublic)
- Video: A quick explanation of Docker and what it can do for business (TechRepublic Video)
- How to deploy and use a MySQL Docker container (TechRepublic)
- How to automatically update Docker containers with Watchtower (TechRepublic)
- How to create and manage Docker networks (TechRepublic)
Jack Wallen is an award-winning writer for TechRepublic and Linux.com. He’s an avid promoter of open source and the voice of The Android Expert. For more news about Jack Wallen, visit his website jackwallen.com.