Skip to content
Blog

Container Ergonomics: Shell Tricks and Daily Aliases

Boost developer productivity with custom Docker CLI aliases, Go template formatting, interactive shell attach helpers, auto-completion, and fuzzy finder integrations.

Published on • November 17, 2026

AI Assistant

Engineers working with Docker daily execute dozens of repetitive shell commands: checking running processes (docker ps), inspecting logs (docker logs -f), attaching interactive shells (docker exec -it ... bash), and purging stopped containers (docker system prune).

By default, Docker CLI output can be verbose, wrapping line lengths awkwardly across standard terminal windows. Configuring targeted shell aliases, custom formatting templates, and interactive fuzzy finders drastically reduces keystrokes and enhances daily container ergonomics.


1. Cleaning Up docker ps with Custom Formats

The default output of docker ps frequently truncates image names and wraps long port mappings across multiple lines.

Modern Go Template Formatting

You can pass custom Go format templates to docker ps using the --format flag:

docker ps --format "table {{.ID}}\t{{.Names}}\t{{.Status}}\t{{.Ports}}\t{{.Image}}"

Output:

CONTAINER ID   NAMES          STATUS          PORTS                    IMAGE
a1b2c3d4e5f6   api-server     Up 2 hours      0.0.0.0:8080->8080/tcp   node:22-alpine
7f8e9d0c1b2a   postgres-db    Up 2 hours      0.0.0.0:5432->5432/tcp   postgres:16-alpine

Making It Default via ~/.docker/config.json

To apply this clean formatting permanently to every docker ps call without aliases, add a psFormat entry to your Docker client configuration (~/.docker/config.json):

{
  "psFormat": "table {{.ID}}\\t{{.Names}}\\t{{.Status}}\\t{{.Ports}}\\t{{.Image}}"
}

2. Essential Daily Shell Aliases

Add these productivity aliases to your ~/.bashrc or ~/.zshrc:

# Custom process listing
alias dps="docker ps --format 'table {{.ID}}\t{{.Names}}\t{{.Status}}\t{{.Ports}}'"
alias dpsa="docker ps -a --format 'table {{.ID}}\t{{.Names}}\t{{.Status}}\t{{.Image}}'"

# Container lifecycle shortcuts
alias dstop='docker stop $(docker ps -q)'           # Stop all running containers
alias drm='docker rm $(docker ps -a -q)'            # Remove all stopped containers
alias dprune='docker system prune -af --volumes'    # Aggressive cleanup of unused images/volumes/networks

# Quick image & volume inspection
alias dimg="docker images --format 'table {{.Repository}}:{{.Tag}}\t{{.ID}}\t{{.Size}}\t{{.CreatedSince}}'"
alias dvol="docker volume ls"

3. Intelligent Shell Attachment Helper (dexec)

Connecting to a running container’s shell usually requires guessing whether it has /bin/bash, /bin/sh, or ash installed.

Add this smart shell function to your shell configuration:

# Smart container shell attach function
dexec() {
  if [ -z "$1" ]; then
    echo "Usage: dexec <container-name-or-id>"
    return 1
  fi
  
  # Try bash first; fall back to sh if bash is missing
  docker exec -it "$1" /bin/bash 2>/dev/null || docker exec -it "$1" /bin/sh
}

Usage:

dexec api-server

4. Interactive Container Search with fzf

If you have fzf (Fuzzy Finder) installed, you can eliminate copy-pasting container IDs entirely.

Interactive Shell Exec (dfexec)

Interactively search through running containers and attach a shell instantly:

dfexec() {
  local cid
  cid=$(docker ps --format "{{.ID}} | {{.Names}} | {{.Image}}" | fzf | awk '{print $1}')
  [ -n "$cid" ] && (docker exec -it "$cid" /bin/bash 2>/dev/null || docker exec -it "$cid" /bin/sh)
}

Interactive Real-Time Logs (dflog)

Fuzzy search containers and stream their logs:

dflog() {
  local cid
  cid=$(docker ps -a --format "{{.ID}} | {{.Names}} | {{.Image}}" | fzf | awk '{print $1}')
  [ -n "$cid" ] && docker logs -f --tail 200 "$cid"
}

5. Setting Up Docker CLI Auto-Completion

Enabling tab completion allows your terminal to auto-complete container IDs, image names, subcommands, and flags.

For Zsh (~/.zshrc):

If using Oh My Zsh, enable the docker plugin in your .zshrc:

plugins=(git docker docker-compose)

For standard Zsh, enable tab completion via compdef:

mkdir -p ~/.zsh/completion
docker completion zsh > ~/.zsh/completion/_docker
fpath=(~/.zsh/completion $fpath)
autoload -Uz compinit && compinit

For Bash (~/.bashrc):

# Load Docker completion for Bash
if command -v docker >/dev/null 2>&1; then
  source <(docker completion bash)
fi

Complete Ergonomic Snippet for ~/.zshrc / ~/.bashrc

# --- Docker Ergonomics Suite ---
alias dps="docker ps --format 'table {{.ID}}\t{{.Names}}\t{{.Status}}\t{{.Ports}}'"
alias dpsa="docker ps -a --format 'table {{.ID}}\t{{.Names}}\t{{.Status}}\t{{.Image}}'"
alias dprune="docker system prune -af --volumes"

dexec() {
  [ -z "$1" ] && { echo "Usage: dexec <container>"; return 1; }
  docker exec -it "$1" /bin/bash 2>/dev/null || docker exec -it "$1" /bin/sh
}

dflog() {
  local cid=$(docker ps -a --format "{{.ID}} | {{.Names}}" | fzf | awk '{print $1}')
  [ -n "$cid" ] && docker logs -f --tail 200 "$cid"
}
# -------------------------------

Takeaway: Investing five minutes to configure terminal shortcuts, custom Go formatting templates, smart shell functions, and fzf search utilities turns noisy, repetitive Docker CLI tasks into smooth, single-keystroke commands.


Sources