簡體   English   中英

使用 Jenkins shell 運行 ''docker exec -i docker-name bash" 無響應

[英]use Jenkins shell run ''docker exec -i docker-name bash" no response

when I run "docker exec -it docker-name bash" on centOS7 service,it will go into docker container and can run " python xx.py config.yaml " to execute some works. but if I use Jenkins shell run "docker exec -it docker-name bash" ,it will have no response,I write "python xx.py config.yaml " behind,Jenkins show [ python: can't open file 'xxx. py': [Errno 2] No such file or directory ] ,I think this error is not into the docker container,so can't find the python file that in the docker container.How can I enter the docker container with Jenkins shell.

When you run docker exec -it docker-name bash , you get an interactive shell inside the container that gets connected to your console and the next command you type to the console is executed in that shell.

但是 Jenkins 沒有控制台。 它正在執行一個腳本,標准輸入連接到 null 設備(讀取時總是返回文件結尾)。 所以實際上它正在執行相當於

docker exec -it docker-name bash </dev/null/dev/null是 null 設備並且<將其連接到命令的標准輸入)。 如果您在控制台上執行此操作,則不會發生任何事情,您將再次獲得原始提示。

但是在這種情況下,您根本不必也不應該運行 bash。 你給docker exec你想在容器中運行的命令,它在那里運行它。 所以你只是做

docker exec -i docker-name python xx.py config.yaml

並且運行 python 命令,打印任何 output 並且當命令結束時,再次與容器斷開連接。

我省略了-t因為它指示 docker 使用終端(控制台),但是 Jenkins 沒有任何控制台,只有-i ,指示它連接標准輸入、標准輸出和標准錯誤,就足夠了。

現在還有一種方法可以在 bash 的標准輸入上發送命令,類似於控制台的操作,但我強烈建議在嘗試之前閱讀 bash 的文檔。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM