Skip to content

Instantly share code, notes, and snippets.

@aristidesneto
Last active May 15, 2024 12:20
Show Gist options
  • Save aristidesneto/8055d982f15d8f4cfb361df62c168ba8 to your computer and use it in GitHub Desktop.
Save aristidesneto/8055d982f15d8f4cfb361df62c168ba8 to your computer and use it in GitHub Desktop.
Get Dockerfile from Docker Image
# 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