DevOps Tools 2023

Docker Exec Shortcut

Bash Script for Simplified Docker Container Access

Duration

2 Days

Year

2023

Technologies

Bash Docker CLI Shell Scripting Linux Unix

The Challenge

When working daily with Docker containers, the complete `docker exec -it CONTAINERNAME /bin/bash` command always had to be typed to access containers. This was time-consuming and error-prone, especially with longer container names or when working with multiple containers simultaneously.

The Solution

An intelligent Bash script that lists all running containers and provides a numbered selection. Alternatively, the container name can be passed directly as a parameter. The script supports both interactive selection and direct calls and can be made available system-wide as an alias.

Implementation

The script uses `docker ps` with formatted output to extract container names. It implements input validation, error handling, and supports both interactive and direct calls. An alias system enables global availability. The script is MIT-licensed and fully documented.

Results

A productive tool that significantly increases Docker workflow efficiency. Reduces typing errors, saves time, and improves developer productivity. The script has been adopted by the community and provides a user-friendly alternative to complex Docker commands.

Key Features

Interactive Selection

Numbered list of running containers for easy selection

Direct Access

Direct container access by specifying name as parameter

Global Alias

System-wide availability through shell alias configuration

Gallery

Quick Installation

Option 1: Interactive Selection

List all running containers and select one

./docker-selector.sh
Option 2: Direct Call

Specify container name directly

./docker-selector.sh cdn
Debian 12 Example
# Download script
sudo curl -JLO https://raw.githubusercontent.com/disisto/docker-exec-shortcut/refs/heads/main/docker-selector.sh
# Make executable
sudo chmod a+x docker-selector.sh
# Setup alias
echo 'alias dcon="/home/${USER}/.docker-selector.sh"' >> ~/.bashrc
source ~/.bashrc

Source Code

This project is open source and available on GitHub under MIT license.

View on GitHub