herchu
herchu

Reputation: 946

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

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?

Upvotes: 5

Views: 3900

Answers (2)

Gianmarco Carrieri
Gianmarco Carrieri

Reputation: 891

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/

Upvotes: 1

chepner
chepner

Reputation: 530970

Use the -t option (twice) with ssh:

ssh -tt -i myKey user@remoteHost docker exec -it myContainer /bin/bash

Upvotes: 9

Related Questions