I want to connect to a remote running Docker container directly with ssh. Normally I can
$ ssh -i privateKey user@host
$ docker ps #which will list all running containers
$ docker exec -it ***** bash deploy.sh # ***** is container id and this line run a deployment script
But I need to run this script from a Jenkins pipeline where I have only one chance. After many trying, I come up with this
$ ssh -tt -i ~/privateKey user@host docker exec -it $(docker ps | grep unique_text | cut -c1-10) /bin/bash deploy.sh
Which have not help my plight because it returns
"docker exec" requires at least 2 arguments.
Which actually mean the command is truncated here $(docker ps | grep ...
My Solution
sh 'ssh -tt -i $FILE -o StrictHostKeyChecking=no $USER@$HOST /bin/bash -c \'"docker exec -it $(docker ps | grep unique_text | cut -c1-10) bash start.sh"\''




