HomeTechnologyNewsHow to manage Docker from your terminal with Lazydocker TUI

How to manage Docker from your terminal with Lazydocker TUI

- Advertisement -
- Advertisement -
- Advertisement -
- Advertisement -

[ad_1]

Lazydocker is an open source terminal interface for managing your Docker environment. It gives you a powerful control surface to interact with containers, images, and volumes. Lazydocker makes it quick and easy to inspect Docker objects without repeating lengthy terminal commands.

The standard Docker CLI is not designed for ongoing monitoring or rapid problem investigation. Finding a problem with a service often requires at least three commands: first listing its containers with docker psthen interacting with the possible culprit (docker restart <id>), and finally check that the change has been effective by repeating docker ps. Lazydocker allows you to perform this sequence from a single screen while continuously monitoring logs and activity.

Lazydocker wraps up much of the docker CLI functionality in an automatically updated Terminal User Interface (TUI). You can monitor all the containers and services running on your Docker host in a terminal window. It includes real-time resource usage graphs, image layer inspection tools, and quick actions to stop, restart, and prune your objects.

Installing Lazydocker

Lazydocker is available for Linux, macOS, and Windows through several different channels. It is present in the Homebrew and Chocolatey package managers or can be downloaded directly from the project’s GitHub releases page.

The official installation script is the easiest way to get started on a Linux system. This will download the correct binary for your platform and deposit it on your $HOME/.local/bin directory.

$ curl https://raw.githubusercontent.com/jesseduffield/lazydocker/master/scripts/install_update_linux.sh | bash

Run lazydocker --version To check the operation of your installation:

$ lazydocker --version
Version: 0.18.1
Date: 2022-05-11T12:14:33Z
BuildSource: binaryRelease
Commit: da650f4384219e13e0dad3de266501aa0b06859c
OS: linux
Arch: amd64

Using Lazydocker

run the lazydocker command without any arguments to start the Lazydocker TUI.

lazydocker image

The screen is divided into two horizontal panels. The left side allows you to switch between different Docker objects such as containers, images, and volumes. The right panel is used to monitor and interact with the currently selected object.

The active object is highlighted in brighter text. Use the up/down arrow keys to move between items in the focused panel. The left/right arrow keys move the focus between different panels. If you’re in the Containers panel, pressing the right arrow key will move you to the Images panel below, for example. Pressing enter always brings the right pane into focus. You can also move between panels and objects by clicking on them with the mouse on compatible skins.

Lazydocker help menu image

Help is always available when you use Lazydocker; pressing the x The key will display a keyboard shortcut reference.

Work with containers

The Containers panel is where you will normally spend most of your time. Only running containers are shown by default; pressing the e key will also include the stopped and hidden ones. Each container displays its current CPU consumption next to its name.

The default selection of a container displays its records on the right side of the screen. Don’t worry if no logs are shown at first: Lazydocker only prints lines written within the last hour, to avoid excessive resource consumption.

Other information panels are available in the tab strip at the top of the screen. Click on the tabs or use the [ and ] keys to move between them.

The Statistics tab provides live graphs of the container’s CPU and memory consumption. Scrolling down the panel provides more information about network input and output, as well as the full statistics output produced by the Docker daemon. Any of these metrics can be graphed by customizing your Lazydocker setup.

Lazydocker container graphics image

The Env tab provides a simple key-value list of environment variables set in the container. Config provides detailed information about the container, including its tags and the JSON output of docker inspect. The final top panel shows the processes running inside the container.

You can perform the following actions against containers by selecting them and then pressing a key:

  • r – Restart the container.
  • s – Stop the container. A confirmation message is displayed.
  • d – Remove the container. A confirmation message is displayed.
  • E – Throw a new shell into the container. This takes you out of the Lazydocker interface. It will automatically return to you when you exit the container and then press the Enter key.

Carrying out bulk container actions

Lazydocker includes some bulk actions that target multiple containers simultaneously. press the b to view the menu and select an option:

Lazydocker container bulk actions menu image

The facility allows you to stop and remove multiple containers in one operation. This helps you quickly restore a clean slate when you’re experimenting with different containers and images.

Add custom stat charts

Lazydocker supports graphing of arbitrary statistics using any metric reported by Docker. Scroll down the Statistics pane to see the JSON statistics produced by the Docker daemon. Find a value to plot and make a note of its position in the JSON object structure, such as ClientStats.networks.eth0.rx_bytes. This metric records the network traffic received by the container.

Lazydocker container metrics image

Open your Lazydocker configuration file by selecting the Project panel and then pressing the button o wrench. You can also access the file directly from your file system; you will usually find it in ~/.config/lazydocker/config.yml on Linux. Add the following content to the file:

stats:
  graphs:
  - caption: CPU (%)
    statPath: DerivedStats.CPUPercentage
    color: blue
  - caption: Memory (%)
    statPath: DerivedStats.MemoryPercentage
    color: green
  - caption: Network received (%)
    statPath: ClientStats.Networks.Eth0.RxBytes
    color: yellow

Restart Lazydocker and then go to the statistics of a container. You should see that incoming network bandwidth is now graphed in addition to the default CPU and memory consumption metrics. Take care that the statPath The field in your config file needs to be converted to a consistent camel case as shown above.

Lazydocker container graphics image

work with images

The Images section displays information about each image you select. The right pane provides a synopsis of the image’s name, ID, tags, and size. It then lists all the layers within your image, including their size and the command that created them.

Lazydocker images screen image

pressing the d The key will display a message allowing you to delete the selected image. The bulk actions menu accessed with b provides an option to clean up all unused images that exist on your host.

work with volumes

The Volumes section has similar functionality to Images. Information about the selected volume is displayed in the right pane, including its mount point, labels, and active storage controller. Pressing d allows you to remove the volume while the bulk actions menu b provides an option that removes all unused volumes.

Lazydocker volumes screen image

Lazydocker and Docker Compose

Lazydocker has good built-in support for Docker Compose projects. Launch Lazydocker from a directory containing a docker-compose.yml The file will present an altered version of the interface that groups its containers into “Services” and “Independent Containers” panes. Services shows the containers defined by your Docker Compose configuration; Standalone containers represent all other containers running on your host.

image of viewing a Docker Compose stack in Lazydocker

Compose’s user interface design also enables additional features in the Project panel at the top left of the screen. Moving focus to this panel will display the combined logs from all the services in your Compose stack on the right. Another tab, “Docker-Compose Config”, shows the contents of your docker-compose.yml proceedings.

Summary

Lazydocker is a versatile tool for advanced Docker users. Provides a centralized view of your container environment within a single terminal window.

While most Docker user interfaces are web or desktop based, Lazydocker sticks to the simplicity of a terminal experience. This makes it a great choice for people who like the style of CLIs but don’t want to remember and repeat handwritten commands. Lazydocker is a standalone binary that runs on your host, so it’s easy to deploy and configure. It also avoids the security concerns of using a web application to interact with Docker.

[ad_2]

- Advertisement -
- Advertisement -
Must Read
- Advertisement -
Related News
- Advertisement -