Created
February 11, 2019 15:36
-
-
Save wsgac/9067bed034fb9e478343b6feb02daca9 to your computer and use it in GitHub Desktop.
Graphical selectors for Docker containers
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- 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 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
go-to-container
- Select Docker container from a graphical menu and connect to it viadocker exec
get-logs-for-container
- Select Docker container from a graphical menu and view its logs