我正在使用Docker-pyAPI来处理和操作Docker
容器。在API
中,put_archive()
函数期望data
字段以字节为单位。
因此,使用tarfile
库,我有:
import tarfile
import io
container = client.create_container(image="myimage", command="/bin/bash")
source = "~/.ssh/id_rsa.pub"
tarfile = create_tar_file(path=source, name="keys.tar")
# tarfile = "keys.tar"
# How can I read the tar file was a BytesIO() object?
data = io.BytesIO()
client.put_archive(container=container, path="/tmp", data=data)
API说:
put_archive
(container
,path
,data
)Insert a file or folder in an existing container using a tar archive as source.
Parameters:
container (str) – The container where the file(s) will be extracted.
path (str) – Path inside the container where the file(s) will be extracted. Must exist.
data (bytes) – tar data to be extractedReturns:
True
if the call succeeds.Return type: (bool)
Raises:
docker.errors.APIError
– If the server returns an error.
我的问题是:
如何将tar文件作为BytesIO()
读取,以便将其传递给put_archive()
函数?
您可以这样做(未经测试,因为我没有安装
Docker-py
):相关问题 更多 >
编程相关推荐