简体   繁体   English

运行 docker-compose over ssh call tr​​ough gitlab CI/CD to amazon linux AMI EC2

[英]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 =>为了恢复,我想通过从 gitlab ci cd runner 到我的 amazon ec2 ami 的 ssh 命令运行 docker-compose,并且只有以下命令有效 =>

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"我试过用双引号: 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 ...例如,当我尝试在 Windows 终端下运行命令时,使用双引号运行它没有问题...

That is because the command interpreter in Windows will behave differently than the bash in Linux.这是因为 Windows 中的命令解释器的行为与 Linux 中的 bash 不同。
See " How to make Windows command prompt treat single quote as though it is a double quote? "请参阅“如何使 Windows 命令提示符将单引号视为双引号?

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.在 Win32 程序中,将命令行拆分为“单词”——C 和 C++ 语言中的程序将 NUL 终止的多字节字符串视为传递给main()的参数数组——是运行时库的范围。那些程序。

On Unices and Linux, the shell does the word splitting, because the operating system actually works in terms of an argument string array.在 Unices 和 Linux 上,shell 进行分词,因为操作系统实际上是根据参数字符串数组工作的。
This is not the case for Win32.这不是 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.在 Win32 上,操作系统本身以命令尾的形式运行:一个长字符串,其中仍然包含一个最初在命令行上键入的所有引号。

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.因此,在您的情况下,“docker-compose -v”可以在 Windows 上运行,但在 Linux bash 中不行,因为它的外壳会删除引号,并且您会得到两个字符串,而不是一个docker-compose -v命令。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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