Skip to content

Instantly share code, notes, and snippets.

@wsgac
Created February 11, 2019 15:36
Show Gist options
  • Save wsgac/9067bed034fb9e478343b6feb02daca9 to your computer and use it in GitHub Desktop.
Save wsgac/9067bed034fb9e478343b6feb02daca9 to your computer and use it in GitHub Desktop.
Graphical selectors for Docker containers
# -*- bash -*-
# These functions require 'dmenu', available as part of the Suckless Tools package
# Ubuntu/Debian: sudo apt install suckless-tools
# Select Docker container from Dmenu and return its ID
function select-container {
echo $(docker ps --format 'table {{.Image}}\t{{.ID}}\t{{.Status}}\t{{.Names}}' | tail -n +2 | dmenu -l 10 | awk '{print $2}')
}
# Go to desired Docker container based on Dmenu selection
function go-to-container {
container=$(select-container)
if [[ ! -z $container ]]; then
docker exec -it $container /bin/bash || \
docker exec -it $container /bin/sh
fi
}
# View logs from desired container based on Dmenu selection
function get-logs-for-container {
container=${1:-$(select-container)}
if [[ ! -z $container ]]; then
docker logs -f $container
fi
}
@wsgac
Copy link
Author

wsgac commented Feb 11, 2019

  • go-to-container - Select Docker container from a graphical menu and connect to it via docker exec
  • get-logs-for-container - Select Docker container from a graphical menu and view its logs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment