Skip to content

Instantly share code, notes, and snippets.

@roshane
Last active March 4, 2021 01:50
Show Gist options
  • Save roshane/130e91acd525bfc9960938c6dd44a33e to your computer and use it in GitHub Desktop.
Save roshane/130e91acd525bfc9960938c6dd44a33e to your computer and use it in GitHub Desktop.
login to docker container as root user #containerlogin #docker #root #container #root login
#!/bin/bash
usageMessage="Usage: $> docker-container-in.sh {container name}"
if [[ -z $1 ]]
then
echo $usageMessage
exit 1
fi
#get running container id
containerId=$(docker ps | grep $1 | cut -d' ' -f1)
echo "container id [$containerId] found for running container named [$1]"
echo "logging into [$1 $containerId] as root user"
docker exec -u0 -it $containerId bash
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment