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.

Logo

权威|前沿|技术|干货|国内首个API全生命周期开发者社区

更多推荐