Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/bash/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/docker/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Bash 如何执行在容器内打开并继续的脚本_Bash_Docker_Interactive - Fatal编程技术网

Bash 如何执行在容器内打开并继续的脚本

Bash 如何执行在容器内打开并继续的脚本,bash,docker,interactive,Bash,Docker,Interactive,您好,我想创建一个脚本,用docker容器启动一个交互式会话,然后从该容器的文件系统读取一个文件(可能还有更多) 如何使bash脚本中的命令在该会话中执行 myscript.sh docker exec -it server0 bash cat dock.txt --this file is in the container filesystem and i want to see it //do more stuff in the filesystem cat dock.txt ls

您好,我想创建一个脚本,用docker容器启动一个
交互式会话
,然后从该容器的文件系统读取一个文件(可能还有更多)

如何使
bash
脚本中的命令在该会话中执行

myscript.sh

docker exec -it server0 bash
cat dock.txt  --this  file is in the container filesystem and i want to see it
//do more stuff in the filesystem
cat dock.txt  
ls -la
//do more stuff in the filesystem
//do more stuff in the filesystem
docker exec -it -v ./myscript.sh:/myscript.sh server0 /myscript.sh
选择1

您可以在中添加多个操作:

docker exec server0 /bin/sh -c "cmd1;cmd2;...;cmdn"  
选择2

使用volume(-v)参数从本地文件夹添加脚本,然后在docker内执行:

docker exec -it -v ./myscript.sh:/myscript.sh server0 /myscript.sh 
myscript.sh

docker exec -it server0 bash
cat dock.txt  --this  file is in the container filesystem and i want to see it
//do more stuff in the filesystem
cat dock.txt  
ls -la
//do more stuff in the filesystem
//do more stuff in the filesystem
docker exec -it -v ./myscript.sh:/myscript.sh server0 /myscript.sh
start.sh

docker exec -it server0 bash
cat dock.txt  --this  file is in the container filesystem and i want to see it
//do more stuff in the filesystem
cat dock.txt  
ls -la
//do more stuff in the filesystem
//do more stuff in the filesystem
docker exec -it -v ./myscript.sh:/myscript.sh server0 /myscript.sh
本地启动脚本:

./start.sh