Skip to content

Make quick adjustments via Docker exec without having to type the entire docker exec -it CONTAINERNAME /bin/bash command into the CLI when needed.

License

Notifications You must be signed in to change notification settings

disisto/docker-exec-shortcut

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 

Repository files navigation

docker exec Shortcut

Make quick adjustments via Docker exec without having to type the entire docker exec -it CONTAINERNAME /bin/bash command into the CLI when needed.

Option 1: Get list

List all running containers and let select one of them. In this example 12 for Docker container named cdn.
./docker-selector.sh

Option 2: Direct call

Direct selection with the specification of the desired container. In this example cdn for Docker container named cdn.
./docker-selector.sh cdn

Optional: Bash/Zsh Alias

To connect to the container regardless of where you are in the CLI, you can also create an alias.

  1. Open your shell configuration file. Depending on the shell you're using, this might be ~/.bashrc, ~/.bash_profile, ~/.zshrc, or similar.

  2. Add the following line to the end of the file to create an alias for the dcon command:

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.

  1. 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

  1. Now, you can run the dcon command from anywhere to execute your script. For example:

dcon cdn

Example for Debian 12 (Bookwork)

sudo apt install curl nano

sudo curl -JLO https://github.com/disisto/docker-exec-shortcut/blob/main/docker-selector.sh

sudo chmod a+x docker-selector.sh

sudo nano sudo nano .bashrc

Add the line alias dcon="/home/username/docker-selector.sh" at the end of the file and save with the key combination "CTRL" + "X", "Y".

source ~/.bashrc

dcon

About

Make quick adjustments via Docker exec without having to type the entire docker exec -it CONTAINERNAME /bin/bash command into the CLI when needed.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages