Tuesday, 23 January 2018

Docker - Login into new TTY with a Running Container

Sometime we need to access the container from another shell in order to run some tail -f log/* or examine some files. so this post will help you to run a another shell with same container id.

You can run a new tty using docker exec -it [container-id] bash command.

To make life easier, I created the script below and placed it at /usr/bin/docker-tty.



if [ "$#" -ne $EXPECTED_NUM_ARGS ]; then
    # user didn't specify which container ID, assume the latest one
    CONTAINER_ID=`/usr/bin/docker ps -q --no-trunc | /bin/sed -n 1p`
    /usr/bin/docker exec -it $CONTAINER_ID env TERM=xterm bash
    # enter the container the user specified
    /usr/bin/docker exec -it $1 env TERM=xterm bash

Now make it executeable:

sudo chmod +x /usr/bin/docker-tty

Now you can just run docker-tty $CONTAINER_ID to enter into new tty. but if you want to enter the last container you spawned.so you run the command docker-tty without having to lookup the id.

Featured post

How to create dynamic schema in mongodb

Sometime what we need in our application is to create mongodb schema for collection and some of our collection schema are same but names are...

Popular Posts