Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How get file from docker container in python

Tags:

python

docker

client = docker.from_env()
data = client.containers.run("namecontainer:1.0", ['param'],detach=True)
file_json = data.get_archive(data, '/wd/out.json')

How make it? How get file out.json? I don't understand.

like image 855
Oleksii Cheban Avatar asked May 08 '26 01:05

Oleksii Cheban


1 Answers

from io import BytesIO

client = docker.from_env()
data = client.containers.run("deep_analize/show_exploit:1.0", ['Apache 1.3.42'], detach=True)
sleep(5)
file_json = data.get_archive('/wd/out.json')
stream, stat = file_json
file_obj = BytesIO()
for i in stream:
    file_obj.write(i)
file_obj.seek(0)
tar = tarfile.open(mode='r', fileobj=file_obj)
text = tar.extractfile('out.json')
q = text.read()
print(q)
like image 52
Oleksii Cheban Avatar answered May 10 '26 13:05

Oleksii Cheban



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!