Created
November 27, 2017 13:14
-
-
Save Razikus/7feb97133971d8a800b43358326c2dc7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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