Created
October 23, 2021 21:18
-
-
Save Richard-Barrett/961700129bc8bb3b45914054e904f956 to your computer and use it in GitHub Desktop.
Interactive Script to Make Docker Run Command on Container Inspect Using run.tpl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# ============================================= | |
# Created by: Richard Barrett | |
# Date Created: 10/23/2021 | |
# Purpose: Make Docker Run Command | |
# Company: Mirantis | |
# ============================================= | |
# Documentation: | |
# ======================================================================================== | |
# https://gist.github.com/efrecon/8ce9c75d518b6eb863f667442d7bc679 | |
# ======================================================================================== | |
#set -e | |
# keep track of the last executed command | |
#trap 'last_command=$current_command; current_command=$BASH_COMMAND' DEBUG | |
# echo an error message before exiting | |
#trap 'echo "\"${last_command}\" command filed with exit code $?."' EXIT | |
# System Variables | |
# ================ | |
LIST_CONTAINERS=$(docker ps) | |
# System Functions | |
function request_list_containers { | |
while true; do | |
read -p "Would you like to list all running containers (yes/no)?" yn | |
case $yn in | |
[Yy]* ) echo "======================================="; \ | |
echo " LISTING RUNNING CONTAINERS..."; \ | |
echo "======================================="; \ | |
$LIST_CONTAINERS; \ | |
echo "======================================="; \ | |
break;; \ | |
[Nn]* ) exit;; | |
* ) echo "Please answer yes or no.";; | |
esac | |
done | |
} | |
# Begin Process | |
# ===================== | |
echo "This process will generate a docker run command from a running container" | |
while true; do | |
read -p "Would you like to generate the docker run command (yes/no)?" yn | |
case $yn in | |
[Yy]* ) echo "======================================="; \ | |
echo " Making Docker Run Command..."; \ | |
echo "======================================="; \ | |
request_list_containers; \ | |
echo "What is the container ID/Name?"; \ | |
read CONTAINER; \ | |
docker inspect \ | |
--format "$(curl -s https://gist.github.com/Richard-Barrett/622a597ec7a2c8f4e81790776d73306a)" \ | |
$CONTAINER; \ | |
echo "======================================="; \ | |
echo " Run Command Generated..."; \ | |
echo "======================================="; \ | |
break;; \ | |
[Nn]* ) exit;; | |
* ) echo "Please answer yes or no.";; | |
esac | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment