Skip to content

Instantly share code, notes, and snippets.

@Razikus
Created November 27, 2017 13:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Razikus/7feb97133971d8a800b43358326c2dc7 to your computer and use it in GitHub Desktop.
Save Razikus/7feb97133971d8a800b43358326c2dc7 to your computer and use it in GitHub Desktop.
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