Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
import tarfile
import uuid
import StringIO
import docker
def main():
client = docker.from_env()
container = client.containers.get(uuidOfContainer)
toSave = "blablabla"
tar_unique_filename = str(uuid.uuid4()) + ".tar"
file_unique_filename = str(uuid.uuid4()) + ".txt"
tar =, "w")
stringToSave = StringIO.StringIO()
info = tarfile.TarInfo(file_unique_filename)
info.size = len(stringToSave.buf)
tar.addfile(tarinfo = info, fileobj = stringToSave)
container.put_archive("/data", tar_unique_filename)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment