Is it possible to create an image from a file on a Docker host using the Docker API?
我正在尝试使用Python docker API从Docker主机上的文件创建Docker映像。
客户端在另一台主机上运行,??因此我要避免将文件下载到客户端,然后再将其上传到Docker主机。
此测试:
1 2 3 4 | 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")) |
产生以下输出:
1 2 3 4 5 | {"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主机上的Ubuntu16.04(Xenial Xerus)VM上运行。客户端是在物理Windows10主机上运行的Docker Python API 2.0.2。
查看Docker守护程序代码后,我发现Docker不支持本地文件,并且始终期望URL发出HTTP响应。
因此我通过Docker容器中的HTTP服务器公开了文件并发送HTTP URL。