Last active
July 5, 2022 13:35
-
-
Save nielsonsantana/282953fdef662ee28c8404ed6c3ecf93 to your computer and use it in GitHub Desktop.
Docker Shortcut to singin on docker container by name
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_PS_LINE=`docker ps | awk '{print $1,$2,$NF}' | grep -m 1 $1` | |
CONTAINER_NAME=`echo $DOCKER_PS_LINE | awk '{print $2}'` | |
CONTAINER_ID=`echo $DOCKER_PS_LINE | awk '{print $1}'` | |
if [ -n "$CONTAINER_ID" ]; then | |
echo "Logged in: $CONTAINER_NAME" | |
docker exec -it $CONTAINER_ID bash | |
else | |
echo "No container found for query: '$1'" | |
fi |
Here is my two cents, not every container have bash shell:
DOCKER_PS_LINE=`docker ps | awk '{print $1,$2,$NF}' | grep -m 1 $1`
CONTAINER_NAME=`echo $DOCKER_PS_LINE | awk '{print $2}'`
CONTAINER_ID=`echo $DOCKER_PS_LINE | awk '{print $1}'`
if [ -n "$CONTAINER_ID" ]; then
echo "Logged in: $CONTAINER_NAME"
docker exec -it $CONTAINER_ID sh -c "(bash || ash || sh);"
else
echo "No container found for query: '$1'"
fi
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
dockerenter
Shortcut to enter on docker container by name
Install
Usage
This command search by the container named web and connect using docker exec.