-
-
Save demoulin/ffcfc44302388f5920bc165e95bbb5f1 to your computer and use it in GitHub Desktop.
Added check for running dockers in loop
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 | |
# docker id might be given as a parameter | |
DID=${1} | |
if [[ ! ${DID} ]]; then | |
# get last running docker ID when there is parameter argument | |
DID=$(docker ps -q -l -f status=running) | |
fi | |
if [[ ${DID} ]]; then | |
# get docker and image name for known docker ID | |
NAME_IMAGE=$(docker ps -f status=running --format='{{.Names}} ({{.Image}})' --filter=id=${DID}) | |
if [[ ${NAME_IMAGE} ]]; then | |
echo "Connecting to:" ${NAME_IMAGE} | |
docker exec -i -t ${DID} bash | |
else | |
echo "Failure: not a valid docker ID" | |
fi | |
else | |
echo "No active docker instances running" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment