Docker Container web tty
Tags: docker, kubernetes, uiweekly
Published: 2019-11-20 07:44:08


# Docker Container-web-tty

Connect your containers via a web-tty

![](https://cdn-images-1.medium.com/max/2560/0*npNeWD5333E_E58v.png)

Have you ever tired of typing

![](https://cdn-images-1.medium.com/max/2000/0*B2G0IY7p28DyW-pq.png)

If you like terminal, and still want a better tool to get into the containers to do some debugging or checking.

## Usage

## Using docker

You can start container-web-tty inside a container by mounting docker.sock:

    docker run -dti --restart always --name container-web-tty \
        -p 8080:8080 \
        -v /var/run/docker.sock:/var/run/docker.sock \
        wrfly/container-web-tty
    

    # tail logs
    docker logs -f container-web-tty

## Using Kubernetes

Or you can mount the Kubernetes config file:

    docker run -dti --restart always --name container-web-tty \
        -p 8080:8080 \
        -e WEB_TTY_BACKEND=kube \
        -e WEB_TTY_KUBE_CONFIG=/kube.config \
        -v ~/.kube/config:/kube.config \
        wrfly/container-web-tty

## Using local <-> remote (gRPC)

You can deploy container-web-tty in remote servers, and connect to it via a local container-web-tty. They use gRPC for communication.

This is useful when you cannot get the remote servers or there is more than one server that you need to connect to.

## Remote

Host 192.168.66.1 and 192.168.66.2 both running:

    docker run -dti --restart always --name container-web-tty \
        -p 8080:8080 \
        -p 8090:8090 \
        -e WEB_TTY_GRPC_PORT=8090 \
        -e WEB_TTY_GRPC_AUTH=96ssW0rd \
        -v /var/run/docker.sock:/var/run/docker.sock \
        wrfly/container-web-tty

Notes:

* You can disable the HTTP server by setting WEB_TTY_PORT=-1

* The WEB_TTY_GRPC_AUTH must be the same between all hosts

## Local

    docker run -dti --restart always --name container-web-tty \
        -p 8080:8080 \
        -e WEB_TTY_BACKEND=grpc \
        -e WEB_TTY_GRPC_AUTH=96ssW0rd \
        -e WEB_TTY_GRPC_SERVERS=192.168.66.1:8090,192.168.66.2:8090 \
        wrfly/container-web-tty

Now you will see all the containers of all the servers via [*http://localhost:8080](http://localhost:8080/)*

## Audit exec history and container outputs

    docker run -dti --restart always --name container-web-tty \
        -p 8080:8080 \
        -e WEB_TTY_AUDIT=true \
        -v `pwd`/container-audit:/audit \
        -v /var/run/docker.sock:/var/run/docker.sock \
        wrfly/container-web-tty

After you exec some commands, you will see the inputs and outputs under the container-audit directory, you can use cat or tail -f to see the changes.

## Real-time sharing

    docker run -dti --restart always --name container-web-tty \
        -p 8080:8080 \
        -e WEB_TTY_SHARE=true \
        -v /var/run/docker.sock:/var/run/docker.sock \
        wrfly/container-web-tty

By enabling this feature, you can share the container’s inputs and outputs with others via the share link (click the container’s image to get the link).

## Show-off

List the containers on your machine:

![](https://cdn-images-1.medium.com/max/3200/0*IjVj6tN6uQisipdJ.png)

It will execute /bin/sh if there is no /bin/bash inside the container:

![](https://cdn-images-1.medium.com/max/2000/1*xNPcFf_9dEqJ4_9OKwkkbw.png)

/bin/bash:

![](https://cdn-images-1.medium.com/max/2000/0*a6gYda7aVGyuJNBn.png)

Run the custom command:

![](https://cdn-images-1.medium.com/max/2120/0*8Nz0Q56U5EGPiiat.png)

Get container logs:

![](https://cdn-images-1.medium.com/max/2000/1*-bUth_tmeqJWQ4v23aDHVw.png)