我有一个循环进程在接受键入命令的 docker 容器中运行。目前我必须使用docker attach <container>然后输入我的命令,例如restart退出之前。
据我所知,我无法使用docker exec我想要与之交互的进程已经在运行,那么我是否可以以编程方式将命令传递给docker attach?
编辑:这是运行的程序内部的命令,不是 shell 中可用的命令
如此处所述,您可以使用socat以下方法:echo 'restart' | socat EXEC:'docker attach <container>',pty STDIN
另一个完整的例子:
# Run the program in docker, here bash, in background
docker run -it --rm --name test ubuntu &
# Send "ls -la" to the bash running inside docker
echo 'ls -la' | socat EXEC:'docker attach test',pty STDIN
# Show the result
docker logs test
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1324 次 |
| 最近记录: |