Home > other >  Run docker-compose over ssh call trough gitlab CI/CD to amazon linux AMI EC2
Run docker-compose over ssh call trough gitlab CI/CD to amazon linux AMI EC2

Time:07-11

i've just spend so much time to found out the answer to my question by myself and it was kinda simple but i would like to know if anyone can explain me why it worked only like the following .

to resume i wanted to run a docker-compose over an ssh command from gitlab ci cd runner to my amazon ec2 ami and only the following command worked =>

ssh  -o StrictHostKeyChecking=no  -i $sshKey $user@$host 'docker-compose -v'

i've tried with double quote : ssh -o StrictHostKeyChecking=no -i $sshKey $user@$host "docker-compose -v"

no quote :

ssh  -o StrictHostKeyChecking=no  -i $sshKey $user@$host docker-compose -v 

and for exemple when i try to run the command under windows terminal i got no issue running it with double quote ...

thanks for answers .

CodePudding user response:

That is because the command interpreter in Windows will behave differently than the bash in Linux.
See "How to make Windows command prompt treat single quote as though it is a double quote?"

In Win32 programs, splitting up the command line into "words" — the NUL-terminated multi-byte character strings that programs in the C and C languages see as the argument array passed to main() — is the province of the runtime libraries of those programs.

On Unices and Linux, the shell does the word splitting, because the operating system actually works in terms of an argument string array.
This is not the case for Win32.

On Win32, the operating system itself operates in terms of a command tail: a single long string that still contains all of the quotation marks that one originally typed on the command line.

So in your case, "docker-compose -v" would work on Windows, but no in a Linux bash, as its shell would remove the quotes, and you get two strings, instead of one docker-compose -v command.

  • Related