是否可以使用 Docker API 从 Docker 主机上的文件创建图像?
Is it possible to create an image from a file on a Docker host using the Docker API?
我正在尝试使用 Python docker API 从 Docker 主机上的文件创建 Docker 图像。
客户端 运行 在不同的主机上,所以我想避免将文件下载到客户端然后将其上传到 Docker 主机。
本次测试:
import docker
d = docker.from_env()
print(d.images.client.api.import_image("/data/file.tar", "acme.com/test"))
print(d.images.client.api.import_image("file:///data/file.tar", "acme.com/test"))
产生以下输出:
{"status":"Downloading from http://%2Fdata%2Ffile.tar"}
{"errorDetail":{"message":"parse http://%2Fdata%2Ffile.tar: invalid URL escape \"%2F\""},"error":"parse http://%2Fdata%2Ffile.tar: invalid URL escape \"%2F\""}
{"status":"Downloading from file:///data/file.tar"}
{"errorDetail":{"message":"Get file:///data/file.tar: unsupported protocol scheme \"file\""},"error":"Get file:///data/file.tar: unsupported protocol scheme \"file\""}
Docker 守护程序 1.13 运行 在 ESXi 6 主机上的 Ubuntu 16.04 (Xenial Xerus) 虚拟机上。客户端是物理 Windows 10 主机上的 Docker Python API 2.0.2 运行。
查看 Docker daemon code 后,我发现 Docker 不支持那里的本地文件,并且总是期望来自 URL 的 HTTP 响应。
所以我通过 Docker 容器中的 HTTP 服务器公开文件并发送 HTTP URL。
我正在尝试使用 Python docker API 从 Docker 主机上的文件创建 Docker 图像。 客户端 运行 在不同的主机上,所以我想避免将文件下载到客户端然后将其上传到 Docker 主机。
本次测试:
import docker
d = docker.from_env()
print(d.images.client.api.import_image("/data/file.tar", "acme.com/test"))
print(d.images.client.api.import_image("file:///data/file.tar", "acme.com/test"))
产生以下输出:
{"status":"Downloading from http://%2Fdata%2Ffile.tar"}
{"errorDetail":{"message":"parse http://%2Fdata%2Ffile.tar: invalid URL escape \"%2F\""},"error":"parse http://%2Fdata%2Ffile.tar: invalid URL escape \"%2F\""}
{"status":"Downloading from file:///data/file.tar"}
{"errorDetail":{"message":"Get file:///data/file.tar: unsupported protocol scheme \"file\""},"error":"Get file:///data/file.tar: unsupported protocol scheme \"file\""}
Docker 守护程序 1.13 运行 在 ESXi 6 主机上的 Ubuntu 16.04 (Xenial Xerus) 虚拟机上。客户端是物理 Windows 10 主机上的 Docker Python API 2.0.2 运行。
查看 Docker daemon code 后,我发现 Docker 不支持那里的本地文件,并且总是期望来自 URL 的 HTTP 响应。
所以我通过 Docker 容器中的 HTTP 服务器公开文件并发送 HTTP URL。