# 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}")