[TIL] A good use case for Docker Compose

I am sure it’s not a new discovery, but it was new to me and considering I had whined about it in the past I thought I’d set the record straight. In a previous post, while discovering Docker, I had complained about Docker compose files and how I’d rather just use the docker run command to setup things (hmm, not sure if I actually said the latter or it was more of an implied thing). Since then I had created a bunch of shell scripts for each of the containers I was impelementing as a way of quickly recreating them with the correct volumes, IP addresses, etc. I had single containers anyways and nothing complex that might require orchestration and Docker Compose.

Last week however I chanced upon a video between Scott Hanselman and Chad Metcalf wherein Chad casually mentioned that he uses Docker Compose, even though he has a single container, as that way he can capture all the settings etc. of the container. That was a light-bulb moment for me. Yes, that makes way better sense than having shell scripts to create containers… so since then I have been re-visiting Docker Compose. I made the following for my kea-knot container:

Nothing fancy but I found the solution to one of my previous issues – that of networks and volumes having the project name prefixed to it automatically, along with how to deal with macvlan networks correctly (version 3.x of Compose does not support specifiying gateway & IP range when you define the network) – through a bit of Googling today. Turns out since I create the macvlan network separately anyways, I can just define it as an external network and thus Docker Compose won’t bother with it. And to prevent Docker Compose from prefixing the project or folder name for volumes, I can add a name property.

I think I will start using Docker Compose files a bit more over shell scripts.