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

How to execute script that opens interactive and continues inside container

你好,我想创建一个脚本来启动一个 interactive session 和一个 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

选项 1

您可以在以下位置添加多个操作:

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

选项 2

您使用卷 (-v) 参数从本地文件夹添加脚本,然后在 docker:

中执行它
docker exec -it -v ./myscript.sh:/myscript.sh server0 /myscript.sh 

myscript.sh

cat dock.txt  
ls -la
//do more stuff in the filesystem
//do more stuff in the filesystem

start.sh

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

在本地启动脚本:

./start.sh