Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to ssh+bash into Docker container in a single command

Tags:

bash

docker

ssh

I need to log in to a bash console within a docker container, which runs in a remote host.

The following commands work:

(local)$ ssh -i myKey user@remoteHost
(remote)$ docker exec -it myContainer /bin/bash

Note that I use passwordless authentication with SSH. My scenario is a bit more involved, including a script to get into a single command (which would actually also figure out docker container ID), this is enough to show the problem. When I try to run in a single command, I get the following error:

(local)$  ssh -i myKey user@remoteHost "docker exec -it myContainer /bin/bash"
cannot enable tty mode on non tty input

How can I run this SSH and get past the "cannot enable tty" error?

like image 889
herchu Avatar asked Jan 06 '23 15:01

herchu


2 Answers

Use the -t option (twice) with ssh:

ssh -tt -i myKey user@remoteHost docker exec -it myContainer /bin/bash
like image 180
chepner Avatar answered Jan 12 '23 16:01

chepner


you can use the command (from your pc) docker-machine with this you are able to connect to the docker server (if the api are exposed) an manage the docker like your local environment (docker ps, docker run etc etc) documentation:

https://docs.docker.com/machine/
like image 20
Gianmarco Carrieri Avatar answered Jan 12 '23 17:01

Gianmarco Carrieri