Skip to content

Instantly share code, notes, and snippets.

@zouchao
Last active September 10, 2018 00:49
Show Gist options
  • Save zouchao/eb21fee72f91ec1c6dde2c6b164097bb to your computer and use it in GitHub Desktop.
Save zouchao/eb21fee72f91ec1c6dde2c6b164097bb to your computer and use it in GitHub Desktop.
login rancher docker container
echo '#!/bin/bash
command="docker ps"
for arg in $@; do
command="$command | grep $arg"
done
command="$command | grep -v haproxy | head -1"
if [[ `eval $command` =~ "piledriver" ]]; then
entrance="/bin/sh"
else
entrance="/bin/bash"
fi
container_id=`eval $command | cut -c1-12`
echo "$container_id"
if [ -z "$container_id" ]; then
echo "Not Found~"
else
docker exec -it $container_id $entrance
fi' > ~/tp
chmod +x ~/tp
echo 'alias tp="sudo ~/tp"' >> ~/.bashrc
source ~/.bashrc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment