Make quick adjustments via Docker exec without having to type the entire docker exec -it CONTAINERNAME /bin/bash command into the CLI when needed.
List all running containers and let select one of them. In this example 12 for Docker container named cdn.
./docker-selector.shDirect selection with the specification of the desired container. In this example cdn for Docker container named cdn.
./docker-selector.sh cdnTo connect to the container regardless of where you are in the CLI, you can also create an alias.
-
Open your shell configuration file. Depending on the shell you're using, this might be
~/.bashrc,~/.bash_profile,~/.zshrc, or similar. -
Add the following line to the end of the file to create an alias for the
dconcommand:
alias dcon="/path/to/script/docker-selector.sh"Replace dcon ("docker connect") with a command of your choice (e.g. dexec ("docker exec") or whatever you like).
Replace /path/to/script with the actual path to your script.
- Save the file and run the source command to load the updated alias settings into your current shell session:
source ~/.bashrc # or ~/.bash_profile, ~/.zshrc, depending on the file you edited- Now, you can run the
dconcommand from anywhere to execute your script. For example:
dcon cdnsudo apt install curl nanosudo curl -JLO https://raw.githubusercontent.com/disisto/docker-exec-shortcut/refs/heads/main/docker-selector.shsudo chmod a+x docker-selector.shsudo mv docker-selector.sh .docker-selector.shsudo nano .bashrcAdd the line
alias dcon="/home/${USER}/.docker-selector.sh"at the end of the file and save with the key combination "CTRL" + "X", "Y".
source ~/.bashrcdcon
