Docker : How to access the Dockerfile of an image?

后端 未结 1 1928
清酒与你
清酒与你 2021-01-15 19:06

When I run the command docker images I get the list as shown below.

[root@hadoop01 myjavadir]# docker images

REPOSITORY                          


        
相关标签:
1条回答
  • 2021-01-15 19:56

    see dockerfile from image from centurylinklabs

    https://github.com/CenturyLinkLabs/dockerfile-from-image

    docker history

    on an image will give you the main information, see the doc

    https://docs.docker.com/engine/reference/commandline/history/

    I had written this short Python script which does a little less than dockerfile-from-image

    import subprocess
    import sys
    
    def main():
    
        dockid = sys.argv[1]
        args = ['docker', 'history', dockid]
        proc = subprocess.Popen(args=args, stdout=subprocess.PIPE,
                                stderr=subprocess.STDOUT)
        (stdout, stderr) = proc.communicate() 
        lines = stdout.split('\n')[1:-2]
        lines.reverse()
        for line in lines:
            idlayer = line.split(' ')[0]
            args = ['docker', 'inspect', 
                    "--format", "'{{ ((index .ContainerConfig.Cmd ) 0) }}'",
                    idlayer]
            proc = subprocess.Popen(args=args, stdout=subprocess.PIPE,
                                    stderr=subprocess.STDOUT)
            (stdout, stderr) = proc.communicate() 
            print stdout,
            # print idlayer, stdout,
    
    main()
    
    0 讨论(0)
提交回复
热议问题