Interactive detach from a running docker compose service without termination
Short one.
As you may know, a common annoyance for docker compose users is the default behavior of the docker compose up command: it ensures a (set of) service(es) defined in a configured/accessible docker-compose.yml are up and running. It also attaches to the services stdout log following updates, i.e. remaining in foreground until the services are shutdown/terminate. Upon pressing Ctrl-c to cancel the live log view, not only the log viewing, but also the full set of services is shut down, which is usually not the desired behavior.
Along a set of shortcuts simplifying docker compose operation I therefore also define an alias that allows to detach from the running log-view-process without terminating the services:
alias docker-detach='pgrep -lfa --euid "$USER" docker | grep "/usr" | grep -v "grep" | fzf | cut -d" " -f1 | xargs -i kill -9 {}'
As usual, the alias is probably not ideal but good enough. It allows interactive selection among the running attachments using input filter fzf.
Upon selection of the running command, we extract its pid and pass it to kill -9, causing it to terminate while keeping the actual service alive. The alias may be added to your preferred shells rc file to be set up on login/shell start. (~/.zshrc, ~/.bashrc, ..)