Dear Reader,
I use Lando a lot these days. I’ve got .lando.yaml
files scattered all over my file structure. I love it because it takes the yak shaving out of development. One thing that bothers me though is the fact that every time I spin up a new lando instance and it has a database, it gets a new port number. I have to go find that port number so I can open my SQL editor to tinker. So over the past year I’ve been writing this little script. It’s finally to the point where I think it might be useful to others so I’m sharing it. Also, if I ever lose it, I’ve now got it backed up on my blog. :)
This is a snippet form my .bash_macros
file. It creates the command db
. Now all I need to do when I need to find the port for the database is type db and it shows me all the running db instances and their exported port numbers.
This was written in bash. I use it on Windows WSL running ubuntu but it should run on any standard Linux. Not sure about OSX.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | # Lando DB # Author: Cal Evans # Copyright 2021 All Rights Reserved # License MIT # # Show what Lando (docker ) DB services are running and what port they are # running on # function db() { RUNNING=$(docker ps --format "table {{.Names}}__{{.Ports}}\n" | grep 3306) echo echo "Lando databases running" echo "Instance Name : DB Port" echo "----------------:--------" for THISONE in $RUNNING do INSTANCE=$(echo $THISONE | awk '{print $1}' | awk -F '_' '{print $1}' ) PORT=$(echo $THISONE | awk -F '__' '{print $2}' | awk -F ':' '{print $2}' | awk -F '->' '{print $1}') printf "%-15s : %s\n" $INSTANCE $PORT done echo ""; } |
fClose()
This is one of those “this works for me so I’m sharing in case it works for you too” pieces of code. I didn’t setup a repo for it because I’m not interested in changes. If you do improve it, you blog about it and then we’ll all be the wiser.
Until next time,
I <3 |<
=C=