-
-
Save MioYvo/0d4db8c934e6a124a60d93190bb4b9f6 to your computer and use it in GitHub Desktop.
Docker py put archive example
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 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)) | |
pw_tar.close() | |
container = docker_client.create_container( | |
**container_options | |
) | |
pw_tarstream.seek(0) | |
pr = docker_client.put_archive( | |
container=container['Id'], | |
path='/tmp', | |
data=pw_tarstream | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment