Last active
May 15, 2024 12:20
-
-
Save aristidesneto/8055d982f15d8f4cfb361df62c168ba8 to your computer and use it in GitHub Desktop.
Get Dockerfile from Docker Image
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
# pip install docker | |
import docker | |
from sys import argv | |
cli = docker.APIClient(base_url='unix://var/run/docker.sock') | |
images = cli.images() | |
image_id = argv[-1] | |
commands = [] | |
for i in images: | |
if image_id in i['Id']: | |
history = cli.history(i['RepoTags'][0]) | |
for hist in history: | |
commands.append(hist['CreatedBy']) | |
commands.reverse() | |
for cmd in commands: | |
print(cmd) | |
if not commands: | |
print(f"Image not found: {image_id}") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment