简体   繁体   中英

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

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 ...

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM