Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Docker py put archive example
import tarfile
import time
from io import BytesIO
admin_password = 'xxxxx'
#write password to file
pw_tarstream = BytesIO()
pw_tar = tarfile.TarFile(fileobj=pw_tarstream, mode='w')
file_data = admin_password.encode('utf8')
tarinfo = tarfile.TarInfo(name='pw.txt')
tarinfo.size = len(file_data)
tarinfo.mtime = time.time()
#tarinfo.mode = 0600
pw_tar.addfile(tarinfo, BytesIO(file_data))
container = docker_client.create_container(
pr = docker_client.put_archive(
Copy link

di commented Aug 9, 2016

Thanks for this! It's exactly what I was looking for.

Worth mentioning that calling is pretty important, otherwise you end up putting an empty byte stream. 😃

Copy link

vijaykv1 commented Jan 12, 2021

Was searching around for this bit of code !! Thanks a lot!! 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment