A while ago, I stumbled upon
ctop; a small, yet handy command-line tool to interact with Docker containers and gather essential metrics. You know
docker stats on steroids. The open-source tool is available for free and can be installed directly on Linux and macOS.
ctop, you get more than just fundamental metrics. Overall,
ctop combines the following features in one single tool:
- display memory consumption per container (learn how to limit memory consumption)
- display CPU utilization per container (learn how to limit CPU utilization)
- direct access to the container log stream
- essential container interaction like starting. stopping and so on
- execute commands in containers
I use ctop because it is efficient and straightforward. All features are accessible within just one keystroke.
# Download ctop sudo wget https://github.com/bcicen/ctop/releases/download/v0.7.3/ctop-0.7.3-linux-amd64 -O /usr/local/bin/ctop # change file mod to make it executable sudo chmod +x /usr/local/bin/ctop
Installation with Homebrew:
brew install ctop
# Download ctop sudo curl -Lo /usr/local/bin/ctop https://github.com/bcicen/ctop/releases/download/v0.7.3/ctop-0.7.3-darwin-amd64 # change file mod to make it executable sudo chmod +x /usr/local/bin/ctop
Run It In A Container
Alternatively, you can run
ctop directly inside of a Docker container.
docker run --rm -it --name ctop-container \ --volume /var/run/docker.sock:/var/run/docker.sock:ro \ quay.io/vektorlab/ctop:latest
ctop is simple but efficient. Learn the following keybindings to get most out of
|h||Show help dialog|
|l||Show container logs|
|[ENTER]||Open container menu|
|a||Toggle view (running / all containers)|
|f||Filter view (ESC to close filter view)|
|s||Select sort field|
|r||Reverse sort order|
|o||Open single view for selected container|
Stream Container Logs With CTOP
From the main view, select the desired container using arrow keys and hit
l top access the log stream of the container
Navigate CTOP With The Container Menu
While you are learning the keybindings, you could use the container menu to navigate. Just select a container - arrow keys - and hit
ctop will bring up a contextual menu, showing all available actions in the context of a particular Docker container.
I love the simplicity and efficiency of
ctop. I can access a bunch of container-related features within just one keystroke. It makes investigating super-efficient and increases overall productivity. Do you use another tool to achieve this? I would love to learn about your setup and see other opportunities.