本文介绍十个专门用于操作镜像的 Docker Remote API。
创建一个镜像
镜像可以从两个方式获取:
- 从 registry 中 pull 一个。
- 导入一个。
用法:
POST /images/createPOST /images/create?fromImage=base 获取名叫 base 的镜像。POST /images/create?fromSrc=url 从 url 导入镜像。

Flux7 这里就有一个 BUG。
shell操作中带有&的情况下,是需要非常小心的。
图片中的命令需要改正为:curl -v -X POST "http://localhost:5555/images/create?fromImage=base&tag=latest"
从容器创建镜像
POST /commit

列出镜像
GET /images/json

插入文件
POST /images/(name)/insert
POST /images/test/insert?path=/usr&url=myurl
如图,将 url 提供的文件插入到 name 对应的镜像的 path 目录中。

删除镜像
DELETE /images/(name)

推送镜像到 registry
POST /images/(name)/push

为镜像做标签
POST /images/(name)/tag

搜索镜像
GET /images/search

查看镜像历史
GET /images/(name)/history

构建镜像
POST /build
这个需要解释一下:POST 传入的 Dockerfile 文件必须是 tar.gz 格式。或者不传入 Dockerfile,而是用 remote 参数指定一个,这种情况下不要求格式。
使用 POST 传入文件的用法:

再例如使用 remote 传入 Dockerfile 的 url 用法:
命令 # curl localhost/Dockerfile #用于展示存储Dockerfile的URI
FROM ubuntu
RUN mkdir /myvol
RUN echo "hello world" > /myvol/greating
VOLUME /myvol
命令 # curl -X POST "127.0.0.1:4243/build?t=asd&remote=http%3A%2F%2Flocalhost%2FDockerfile"
命令 # docker images
REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
asd latest 1946f0511bda 36 seconds ago 188.3 MB
本文介绍了通过Docker Remote API进行的十种镜像操作,包括创建、列出、插入文件等,并提供了具体命令实例。
8483

被折叠的 条评论
为什么被折叠?



