我正在尝试使用Docker创建容器。我在跑步:
sudo curl \
-XPOST --unix-socket /var/run/docker.sock \
-d '{"Image":"nginx"}' \
-H 'Content-Type: application/json' \
http://localhost/containers/create但我得到了这样的信息:
{"message":"No such image: nginx:latest"}如果还没有下载图像的话,不应该下载吗?
谢谢。
发布于 2019-10-22 20:18:29
这是预期的行为。REST,用于创建容器,是一步一步的,而'docker‘命令执行多个操作。
使用strace,您可以看到它向API发出的一些POST请求,甚至对于一个简单的docker run hello-world也是如此,包括:
POST /v1.40/containers/create
POST /v1.40/images/create
POST /v1.40/containers/create
POST /v1.40/containers/[hash]/attach
POST /v1.40/containers/[hash]/wait
POST /v1.40/containers/[hash]/start当第一个创建请求失败时,它向前移动并拉出图像,然后重新发出创建。它还需要处理连接到容器和启动容器。为了自己使用API,您需要模拟适当的操作。
API参考甚至呼吁这样做:
大多数客户端命令直接映射到API端点(例如,
docker ps是GET/containers/json)。值得注意的例外是运行容器,它由几个API调用组成。
发布于 2019-10-22 20:04:16
这是预期的行为,如下所示:https://github.com/moby/moby/issues/30658
https://stackoverflow.com/questions/58511200
复制相似问题