Skip to content

obeone/docker-nsenter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 

Repository files navigation

🚀 docker-nsenter

The docker-nsenter script allows you to enter various namespaces of a Docker container, simplifying nsenter commands and making it easy to target running containers.

📥 Installation

  1. Save the docker-nsenter.sh script in a directory within your $PATH. Note: Rename the script to docker-nsenter (without the .sh extension) for optimal compatibility with the ZSH completion script.
mv docker-nsenter.sh /usr/local/bin/docker-nsenter
chmod +x /usr/local/bin/docker-nsenter
  1. If you want to use ZSH autocompletion, install the _docker-nsenter.zsh file:
  • Move the file to your ZSH completion folder:
mkdir -p ~/.zsh/completions
mv _docker-nsenter.zsh ~/.zsh/completions/_docker-nsenter
  • Add the completion folder to your fpath if it’s not already set, and reload your ZSH configuration:
echo 'fpath+=(~/.zsh/completions)' >> ~/.zshrc
source ~/.zshrc
  1. Autocompletion is now enabled! You can start using docker-nsenter with autocompletion by pressing [TAB] after the command name to see available options and running containers.

🛠 Usage

docker-nsenter Command

The docker-nsenter command provides options to enter specific namespaces (network, pid, etc.) of a Docker container using nsenter.

🖥️ Example usage

docker-nsenter --net <container name or ID>

Other example commands:

  • To enter the PID namespace:
docker-nsenter --pid <container name or ID>
  • To enter multiple namespaces, e.g., network and mount:
docker-nsenter --net --mount <container name or ID>

ZSH Completion 🎉

The ZSH completion script provides:

  • nsenter options with both short and long versions, making typing easier.
  • A dynamic list of running Docker container names for quick selection.

⚠️ Note on Command Naming

For optimal ZSH completion functionality, the command should be installed without an extension (docker-nsenter). If you choose to keep the .sh extension, you’ll need to modify the completion script accordingly.

📜 License

This project is licensed under the MIT License.

MIT License

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

🙏 Credits

Created with pride by ZSH Expert GPT and GPT-4o, supervised by obeone

About

Simplified nsenter wrapper to use with docker

Topics

Resources

Stars

Watchers

Forks

Languages