简体   繁体   中英

How to look at a file in a docker image (example: Docker's 'hello-world' image)

I am a newbie to Docker and was doing a docker inspect to the official Docker hello-world image and following is an excerpt of it:

C:\> docker inspect hello-world
[
    {
        "Id": "sha256:2cb0d9787c4dd17ef9eb03e512923bc4db10add190d3f84af63b744e353a9b34",
        "RepoTags": [
            "hello-world:latest"
        ],
        "RepoDigests": [
            "hello-world@sha256:4b8ff392a12ed9ea17784bd3c9a8b1fa3299cac44aca35a85c90c5e3c7afacdc"
        ],
        "Parent": "",
        "Comment": "",
        "Created": "2018-07-11T00:32:08.432822465Z",
        "Container": "6b6326f6afc81f7850b74670aad2bf550c7f2f07cd63282160e5eb564876087f",
        "ContainerConfig": {
            "Hostname": "6b6326f6afc8",
            "Domainname": "",
            "User": "",
            "AttachStdin": false,
            "AttachStdout": false,
            "AttachStderr": false,
            "Tty": false,
            "OpenStdin": false,
            "StdinOnce": false,
            "Env": [
                "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
            ],
            "Cmd": [
                "/bin/sh",
                "-c",
                "#(nop) ",
                "CMD [\"/hello\"]"
            ],
            "ArgsEscaped": true,
            "Image": "sha256:6bc48d210ad4c6bbb74e02e6196a9133b57107033c09e92cac12616cad30ebcf",
            "Volumes": null,
            "WorkingDir": "",
            "Entrypoint": null,
            "OnBuild": null,
            "Labels": {}
        },
        "DockerVersion": "17.06.2-ce",
        "Author": "",
        "Config": {
            "Hostname": "",
            "Domainname": "",
            "User": "",
            "AttachStdin": false,
            "AttachStdout": false,
            "AttachStderr": false,
            "Tty": false,
            "OpenStdin": false,
            "StdinOnce": false,
            "Env": [
                "PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
            ],
            "Cmd": [
                "/hello"
            ],
            "ArgsEscaped": true,
            "Image": "sha256:6bc48d210ad4c6bbb74e02e6196a9133b57107033c09e92cac12616cad30ebcf",
            "Volumes": null,
            "WorkingDir": "",
            "Entrypoint": null,
            "OnBuild": null,
            "Labels": null
        },
        "Architecture": "amd64",
        "Os": "linux",
        "Size": 1848,
        "VirtualSize": 1848,
        "GraphDriver": {
            "Data": {
                "MergedDir": "/var/lib/docker/overlay2/20d0631d9382f954d57631716e227ddbd42a0b383ae5e26241d5cf9fc92cbfe2/merged",
                "UpperDir": "/var/lib/docker/overlay2/20d0631d9382f954d57631716e227ddbd42a0b383ae5e26241d5cf9fc92cbfe2/diff",
                "WorkDir": "/var/lib/docker/overlay2/20d0631d9382f954d57631716e227ddbd42a0b383ae5e26241d5cf9fc92cbfe2/work"
            },
            "Name": "overlay2"
        },
        "RootFS": {
            "Type": "layers",
            "Layers": [
                "sha256:ee83fc5847cb872324b8a1f5dbfd754255367f4280122b4e2d5aee17818e31f5"
            ]
        },
        "Metadata": {
            "LastTagTime": "0001-01-01T00:00:00Z"
        }
    }
]

Questions:

  • I thought one needs to define an Entrypoint to make a container executable (so that when I do docker run hello-world , I get the blob of text that you usually see), but looking at the following output, I see that Entrypoint is null . Any ideas?

  • I can imagine that if I run a container as interactive, I can dig into the file system to look at the files but hello-world image doesn't work in interactive mode.

There are two ways to run an executable in docker

Each runnable docker image needs either a CMD or an ENTRYPOINT. They differ slightly in what forms the root command of the container. See this question for differences Otherwise for all practical purposes they are same

And as you can see from the hello-world image, it has a CMD specified as /hello

  • If you look at the Official Hello-world dockerfile you can see that the CMD is used to execute the program.
  • Because it's created from scratch you won't be able to run docker exec -it [container] /bin/sh

Advanced Additional Resources

Docker Best Practices

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM