docker执行容器内的shell_使用shell脚本在Docker容器内运行脚本
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/bashdocker run -t -i -p 5902:5902 --name "mycontainer" --
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.
更多推荐
所有评论(0)