Created
June 12, 2019 14:59
-
-
Save studiotomi/4dd8e690fe9079af409f7ece9ee02852 to your computer and use it in GitHub Desktop.
Given a string, find id of matching docker container, and return id and name or execute arbitrary command.
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 | |
function containerCommand() { | |
# Given a string, search for the matching running docker containers. | |
# If more than one argument is passed, attempt to run remaning arguments | |
# on that docker container. | |
container=`docker ps --format '{{.ID}} {{.Names}}'1`; | |
shift; | |
if [[ ! -z "$@" ]] | |
then | |
container=`echo -n "${container}" | cut -f1 -d\ ` | |
docker exec -it $container $@; | |
else | |
echo "${container}"; | |
fi | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment