Bash 如何执行在容器内打开并继续的脚本
您好,我想创建一个脚本,用docker容器启动一个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
交互式会话
,然后从该容器的文件系统读取一个文件(可能还有更多)
如何使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