For anyone who manages docker containers, having the right tools can really make an admin session all the better. On the other hand, not having the right tools can transform your day into an exercise in frustration.
With docker, if you’re comfortable with the command line, you probably feel like you have everything you need to get the most out of those containers. But then you see one of the many GUIs available and wish you had more, but without having to go the full-on graphical route. Say, for example, your docker containers are managed from a headless Linux server, and you don’t want to have to install a web-based GUI to get more information and easier management of those deployed containers.
What do you do? What tool exists in the realm between console and GUI?
How about Lazydocker?
Lazydocker was created by Jesse Duffield to help make managing docker containers a bit easier. Simply put, Lazydocker is a terminal UI (written in Golang with the gocui library) for the docker and docker-compose commands. Lazydocker allows you view projects, containers, images, volumes, as well as the logs, stats, configs, and top for your running containers.
Lazydocker also allows you to run bulk commands to stop, remove, and prune containers.
And best of all, Lazydocker is incredibly easy to install and use. I’m going to walk you through the process of doing just that. I’ll be demonstrating on Ubuntu Server 18.04, but you should be able to get Lazydocker installed on just about any Linux distribution that supports the docker engine.
How to Install docker
Before you can install Lazydocker, you must first have docker itself installed. Chances are you already do. If that’s the case, jump down to the Lazydocker install section. Otherwise, let’s install docker.
Open a terminal window and issue the command:
sudo apt-get install docker.io -y
Once that command completes, start and enable the docker daemon with the commands:
sudo systemctl start docker
sudo systemctl enable docker
With the service started and enabled, you’ll then need to add your user to the docker group. If you don’t do this, the only way you can work with the docker commands is by way of sudo, and that’s a security risk. To avoid that, issue the command:
sudo usermod -aG docker $USER
Once you’ve done that, log out and log back in.
You might also want to install docker-compose. To do this, issue the following commands:
sudo curl -L "https://github.com/docker/compose/releases/download/1.23.1/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose
How to Install Lazydocker
Now that you have both docker and docker-compose installed, it’s time to install Lazydocker. The first thing to do is visit the Lazydocker release page and see what the latest version the developer has available. As of March 13, 2020, the most recent release is 0.8. Download that version (assuming your architecture is 64bit) with the command:
Once downloaded, unpack it with the command:
tar xvzf lazydocker*.tar.gz
You should now see three new files:
Install the lazydocker binary file with the command:
sudo install lazydocker /usr/local/bin
To verify the installation, run the command:
You should see all of the relevant release information for Lazydocker (Figure 1).
How to Use Lazydocker with docker
Now that you have Lazydocker installed, let’s deploy a couple of containers and see how it works. First, we’ll deploy an NGINX container with the command:
docker run --name docker-nginx -p 8080:80 -d nginx
Next we’re going to deploy a MySQL container with the command:
docker run --name=mysql01 -d mysql/mysql-server:latest
Now let’s create a volume and then attach it to a container. Create the volume with the command:
docker volume create --name volume1
Now create a directory to mount the volume to with the command:
Next deploy the container with the command:
docker run -d -P --name test-container -v ~/container-data:/data nginx
The above command will print out a container ID. Copy that ID and then attach the volume with the command:
docker attach ID
Where ID is the container ID you copied.
With those containers created, issue the command:
The Lazydocker interface will appear (Figure 2).
With your mouse, you can click on any pane or any listing within a pane. For example, click on the docker-nginx entry and then click on the Logs tab in the right pane. You’ll see all the log entries for the running container (Figure 3).
You can also click on the Stats, Config, or Top tabs to view even more information.
If you type “b” (no quotes) on your keyboard, you’ll see the Bulk Command menu (Figure 4).
From this menu you can stop, remove, and prune all of your containers.
Exit out of Lazydocker by typing “q” (no quotes).
Using Lazydocker with docker-compose
Now we’ll create a docker-compose project, based on WordPress. Create a new directory with the command:
Change into that directory with the command:
Create the YAML file with the command:
In that file, paste the following:
Save and close the file.
Deploy the WordPress container with the command:
docker-compose up -d
Once the container has deployed, issue the lazydocker command from within the ~/wordpress folder and the tool will open with all of the information for this project (Figure 5).
You can now check out the same types of information for the wordpress project as you did with the deployed docker containers.
Lazydocker may not be for everyone, but for those looking for a solution that exists somewhere between the command line and a GUI, this tool can’t be beat. Give it a try and see if it doesn’t quickly become your go-to docker container manager.
Feature image via Lazydocker.