Docker Community Forums

Share and learn in the Docker community.

How can I telnet into a Linux container?

Docker swarm, universal control panel.

We build containers on docker swarm, and then connect to them using the universal control panel and selecting console. The problem with this is the interface is very limited. You cannot copy and paste, and if you leave the screen for even a few seconds when you come back you need to reconnect, losing your command history and putting you back into the default directory.

I would like to know if there is a way to enable telnet in the container so that I can connect to it from another machine on the network using putty. I assume I will have to put something into my startup file in order to accomplish this.

Obviously, doing development in the current configuration it makes any kind of debugging extremely difficult.

This would be bloody easy with Kubernetes, where you are able to exec into any container of any pod in any namespace, regardess where it runs. Docker swarm does not provide an eqivalent solution.

You can only use docker exec with containers locale to a node. You have two ways to do so:
– either connect to the remote terminal of the node’s host via putty/ssh and execute docker exec there
– or register the nodes in docker context and switch the context (as in remote docker enging) before you execute docker exec, which will execut commands in the local terminal, but sends the commands to the target docker engine.

docker exec -it CONTAINERID /bin/sh
/app # telnet
/bin/sh: telnet: not found

/app # apk update
fetch http://dl-cdn.alpinelinux.org/alpine/v3.7/main/x86_64/APKINDEX.tar.gz
fetch http://dl-cdn.alpinelinux.org/alpine/v3.7/community/x86_64/APKINDEX.tar.gz
v3.7.0-243-gf26e75a186 [http://dl-cdn.alpinelinux.org/alpine/v3.7/main]
v3.7.0-229-g087f28e29d [http://dl-cdn.alpinelinux.org/alpine/v3.7/community]
OK: 9051 distinct packages available

/app # apk add busybox-extras
(1/1) Installing busybox-extras (1.27.2-r11)
Executing busybox-extras-1.27.2-r11.post-install
Executing busybox-1.27.2-r7.trigger
OK: 77 MiB in 64 packages

/app # busybox-extras telnet localhost 6900