Skip to content

Instantly share code, notes, and snippets.

Embed
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 = tarfile.open(tar_unique_filename, "w")
stringToSave = StringIO.StringIO()
stringToSave.write(toSave)
stringToSave.seek(0)
info = tarfile.TarInfo(file_unique_filename)
info.size = len(stringToSave.buf)
tar.addfile(tarinfo = info, fileobj = stringToSave)
tar.close()
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