问题描述
我是Docker技术的新手,我正在尝试创建一个用于设置docker容器的shell脚本,我的脚本文件如下所示 #bin / bash
docker运行-t -i -p 5902:5902 - 名称mycontainer--privileged myImage:new / bin / bash
运行此脚本文件将在新调用的bash中运行该容器。
现在我需要从上面给出的shell脚本运行一个已经在容器内的脚本文件(test.sh)(例如:cd /path/to/test.sh&& ./test.sh)
如何做,请随时问问场景是否不清楚。
您可以运行命令在运行容器中使用 docker exec [OPTIONS] CONTAINER COMMAND [ARG ...]
:
docker exec mycontainer /path/to/test.sh
并运行从bash会话:
docker exec -it mycontainer / bin / bash
从那里你可以运行你的脚本或其他。
I am new to Docker technology,I am trying to create a shell script for setting up a docker container, my script file looks like following
#!bin/bash
docker run -t -i -p 5902:5902 --name "mycontainer" --privileged myImage:new /bin/bash
Running this script file will run the container in a newly invoked bash.
Now i need to run a script file (test.sh)which is already inside container from the above given shell script.(eg: cd /path/to/test.sh && ./test.sh)How to do that, please feel free to ask if the scenario is not clear.
You can run a command in a running container using docker exec [OPTIONS] CONTAINER COMMAND [ARG...]
:
docker exec mycontainer /path/to/test.sh
And to run from a bash session:
docker exec -it mycontainer /bin/bash
And from there you can run your script or whatever.
这篇关于使用shell脚本在Docker容器内运行脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!