简体   繁体   English

如何在 docker 容器中使用参数运行本地主机脚本

[英]How to run local host machine script with arguments in a docker container

I'm trying to run a local script in my docker host on a docker container.我正在尝试在 docker 容器上的 docker 主机中运行本地脚本。

I know it is possible to run it using: docker exec -i mycontainer bash < mylocal.sh , but how do I pass arguments to the mylocal.sh using this method.我知道可以使用以下docker exec -i mycontainer bash < mylocal.sh运行它: docker exec -i mycontainer bash < mylocal.sh ,但是如何使用此方法将参数传递给 mylocal.sh 。

Say I want to pass the script contents plus an argument like mylocal.sh argument1假设我想传递脚本内容以及像mylocal.sh argument1这样的mylocal.sh argument1

I don't really want to copy the files over from host to container.我真的不想将文件从主机复制到容器。

您可以使用 -s 选项使用管道将参数传递给 bash 脚本。

docker exec -i mycontainer bash -s argument1 argument2 < mylocal.sh

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

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