Flux7 Docker 系列教程(九):用於鏡像操做的 10 個 Docker Remote API

本系列教程翻譯自 Flux7 Docker Tutorial Series,系列共有九篇,本文譯自原教程最後一篇 Part 9: 10 Docker Remote API Commands for Images
該系列全部文章將參考其餘學習資料翻譯,也會加入本身的學習做爲部分註解。若有錯誤,歡迎指正。docker

本文介紹十個專門用於操做鏡像的 Docker Remote API。shell

建立一個鏡像

鏡像能夠從兩個方式獲取:json

  1. 從 registry 中 pull 一個。
  2. 導入一個。

用法:ubuntu

POST /images/create
POST /images/create?fromImage=base 獲取名叫 base 的鏡像。
POST /images/create?fromSrc=urlurl 導入鏡像。api

clipboard.png

Flux7 這裏就有一個 BUG。
shell操做中帶有 & 的狀況下,是須要很是當心的。
圖片中的命令須要改正爲:curl -v -X POST "http://localhost:5555/images/create?fromImage=base&tag=latest"安全

從容器建立鏡像

POST /commit

clipboard.png

列出鏡像

GET /images/json

clipboard.png

插入文件

POST /images/(name)/insert
POST /images/test/insert?path=/usr&url=myurl

如圖,將 url 提供的文件插入到 name 對應的鏡像的 path 目錄中。curl

clipboard.png

刪除鏡像

DELETE /images/(name)

clipboard.png

推送鏡像到 registry

POST /images/(name)/push

clipboard.png

爲鏡像作標籤

POST /images/(name)/tag

clipboard.png

搜索鏡像

GET /images/search

clipboard.png

查看鏡像歷史

GET /images/(name)/history

clipboard.png

構建鏡像

POST /build

這個須要解釋一下:POST 傳入的 Dockerfile 文件必須是 tar.gz 格式。或者不傳入 Dockerfile,而是用 remote 參數指定一個,這種狀況下不要求格式。學習

使用 POST 傳入文件的用法:ui

clipboard.png

再例如使用 remote 傳入 Dockerfile 的 url 用法: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

結尾

Flux7 系列的 Docker 教程到此結束。

本系列教程的有些文章並非很厚實,也不很使用,因此譯者也正在翻譯其餘的 Docker 文章,包括 Docker 安全、Docker 進階、Docker 實例等系列實用性的文章,歡迎關注 SegmentFault 社區獲取最新信息。

固然,若是你有相關的、很是棒的英文教程能夠用留言的方式推薦給我。

相關文章
相關標籤/搜索