使用Docker Engine API在现有容器中执行命令
我试图通过Docker Engine API在现有的Docker容器中执行命令touch hello.txt
。 如何没有创build文件
我的设置
- 一个ID为
eb4c32cd64ee
正在运行的容器 - 容器
/storage:/home
容量设置/storage:/home
其中/storage
位于主机上,/home
是容器内的文件夹
什么是工作
-
运行
docker exec -it eb4c32cd64ee touch /home/yes.txt
在容器内按预期创build文本文件,该文件也在主机机器/storage
下可见,validation卷正在工作 -
运行
curl --unix-socket /var/run/docker.sock "http:/v1.27/containers/json" -X GET
按预期返回容器列表,validationDocker Engine API在主机上工作 -
按预期方式运行以下命令会返回Exec实例ID
43597e1842d2382f1e00f7751fef963dd83a472172d7f35c8ce8f77839a0b249
curl --unix-socket /var/run/docker.sock \ -H "Content-Type: application/json" -X \ POST http:/v1.27/containers/eb4c32cd64ee/exec \ -d '{"Cmd": ["touch", "/home/new.txt"]}'
什么是不工作
以下命令的预期效果是在容器内创build新文件/home/new.txt
。 但是该文件没有被创build 。
它只是返回{"message":"EOF"}
curl --unix-socket /var/run/docker.sock -X POST \ http:/v1.27/exec/dfbe9918be03955dd06ffd37ba1b7d11e71934a37a614f071cbdd814aa9f3040/start
我在这里错过了什么?