Created
March 6, 2018 19:21
-
-
Save tmuth/e71ac93ffe0252ce296bf8839cecde57 to your computer and use it in GitHub Desktop.
Docker-Bash-Functions
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
function docker_exec { | |
name="${1?needs one argument}" | |
containerId=$(docker ps | awk -v app="$name" '$2 ~ app{print $1}') | |
if [[ -n "$containerId" ]]; then | |
docker exec -it $containerId bash | |
else | |
echo "No docker container with name: $name is running" | |
fi | |
} | |
alias dx='docker_exec $1' | |
function get_container_id { | |
name="${1?needs one argument}" | |
containerId=$(docker ps | awk -v app="$name" '$2 ~ app{print $1}') | |
if [[ -n "$containerId" ]]; then | |
echo ${containerId} | |
else | |
echo "No docker container with name: $name is running" | |
fi | |
} | |
function package_app { | |
containerName="${1?needs one argument}" | |
appName="${2?needs one argument}" | |
containerId=$(get_container_id ${containerName}) | |
SPLUNK_USERNAME=admin | |
SPLUNK_PASS=changeme | |
docker exec -it ${containerId} /bin/bash -c "/opt/splunk/bin/splunk package app ${appName} -auth ${SPLUNK_USERNAME}:${SPLUNK_PASS} " | |
} | |
function docker_copy_out { | |
containerName="${1?needs one argument}" | |
sourcePath="${2?needs one argument}" | |
destPath="${3?needs one argument}" | |
containerId=$(get_container_id ${containerName}) | |
echo "About to copy: ${containerId}:${sourcePath} ${destPath} " | |
docker cp ${containerId}:${sourcePath} "${destPath}" | |
} | |
export SPLK_PKG=/opt/splunk/etc/system/static/app-packages | |
export GIT_APPS="/Users/tmuth/Box Sync/Git/demo-dbconnect/dbconnect/apps/" | |
alias get-orcl-mon-app='docker_copy_out dbx ${SPLK_PKG}/oracle_monitoring.spl "${GIT_APPS}"' | |
alias get-dbx-demo-app='docker_copy_out dbx ${SPLK_PKG}/dbx_demo.spl "${GIT_APPS}"' | |
alias package-apps='package_app dbx oracle_monitoring;package_app dbx dbx_demo;get-orcl-mon-app;get-dbx-demo-app' | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment