Holly's Briars

You are viewing a single post out of many.

If you happen to like what you're reading, go here to read more and unpack the rest of this mess.


Click on a #tag to jump to that post category, or go here to visit the archive.


broot and Docker

  • 2023-08-25
  • 14:22

A while back, I found a neat little tool called broot which is a TUI file manager written in Rust. It claims to be a better way to navigate directories, and I find that claim to be quite the understatement.

When I had the data loss scenario, I copied everything that I could to a directory on the host drive. What I didn't do was copy everything to the data volumes, as I suspended my use of several services. I sort of left the directory intact and forgot about it until Pi-Hole started complaining about insufficient space for log files. On my desktop, I use Disk Usage Analyzer, however that is a GUI application. There is the du for terminal use, and that is just... No.

Since I had started to learn Rust, I figured I could write something. I searched for "rust sort directory by size" and my life changed forever when broot came across my radar. After poking around a bit, I found a launch argument and so...

broot --sort-by-size ~/recovery

...gave me everything I wanted. I went up and down the tree, pressing space bar to enter verb mode, and then rm to remove directories I had already copied. After a few minutes, I recovered over 450 GB of drive space.

I probably could have done that with ranger, but c'mon its 2023. It's haute-coture to use Rust for everything. What does that have to do with Docker you may ask? Well, I just mentioned a "verb". A verb is, aptly put, a command. broot lets me add custom verbs.

Since that server is only used as a Docker host, and I'm constantly messing around with the containers, I decided to do a bit of automation in regards to Docker and the containers. My frequent tasks are:

  • Updating containers
  • (Re)starting and stopping containers
  • Testing new containers

I came up with a few commands to speed up the process, so that I can browse up and down the tree in broot, not having to worry about entering directories, getting paths right, and all of that.

{
    name: Bring up Docker container
    invocation: compose
    execution: "docker compose -f {file} up -d"
    apply_to: file
    leave_broot: false
}
{
    name: Test Docker container
    invocation: test
    execution: "docker compose -f {file} up"
    apply_to: file
    leave_broot: false
}
{
    name: Start Docker container
    invocation: start
    execution: "docker compose -f {file} start"
    apply_to: file
    leave_broot: false
}
{
    name: Stop Docker container
    invocation: stop
    execution: "docker compose -f {file} stop"
    apply_to: file
    leave_broot: false
}
{
    name: Restart Docker container
    invocation: restart
    execution: "docker compose -f {file} restart"
    apply_to: file
    leave_broot: false
}

You will notice that a verb for docker compose -f {file} down is not present, nor is there a verb to update the container images. I simply don't trust myself. I prefer to remove the containers, volumes, images, and networks manually, with their respective commands. As for the updating containers? if you use :latest, FOR SHAME.