0

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.

Kiran
  • 56,921
  • 15
  • 176
  • 161

2 Answers2

1

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

rajeshnair
  • 1,587
  • 16
  • 32
  • Thanks @rajeshnair. Yeah, I am aware of that post actually, but was under the impression that `ENTRYPOINT` is used a standard to have something that `always` runs when a container is run and that `CMD` is used for supplying `defaults` to it. Not sure why Docker's default image doesn't follow this. – Kiran Aug 20 '18 at 18:35
  • 1
    @KiranChalla, well I will assume that's because ENTRYPOINT was introduced later than CMD. Entrypoint came in version 0.5 and initially required ENTRYPOINT and CMD both to be present. It was only in 0.6 that ENTRUPOINT was allowed without CMD. I can understand the confusion it causes as CMD is used to extend the command provided to ENTRYPOINT. My personal practise is to always provide ENTRYPOINT and any extensions to command via docker-compose only – rajeshnair Aug 21 '18 at 14:51
1
  • 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

Ryan Z
  • 60
  • 4