dockerquay.io

Default command for a docker image


How can I know the default command a container runs using a base image without actually creating a new container from the image?

is some concept I am missing here? I am writing a dockerfile using a base image but I dont know what to put in CMD section.


Solution

  • You can always do docker image inspect <image> on the terminal where you will get a bunch of information.

    I run docker image inspect busybox (Just some random image), and I got the following result

    [
        {
            
            "Parent": "",
            "Comment": "",
            "Created": "2021-05-04T00:19:49.531663542Z",
            "Container": "22c781af50cbbf2c31a3fb57c21d4dcfb266d6691441657088db6750d4068d22",
            "ContainerConfig": {
                "Hostname": "22c781af50cb",
                "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 [\"sh\"]"
                ],
                
                "Volumes": null,
                "WorkingDir": "",
                "Entrypoint": null,
                "OnBuild": null,
                "Labels": {}
            },
            "DockerVersion": "19.03.12",
            "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": [
                    "sh"
                ],
                
                "Volumes": null,
                "WorkingDir": "",
                "Entrypoint": null,
                "OnBuild": null,
                "Labels": null
            },
            "Architecture": "amd64",
            "Os": "linux",
            "Size": 1235829,
            "VirtualSize": 1235829,
            "GraphDriver": {
                "Data": {
          },
                "Name": "overlay2"
            },
            "RootFS": {
                "Type": "layers",
            },
            "Metadata": {
                "LastTagTime": "0001-01-01T00:00:00Z"
            }
        }
    ]
    
    

    Here you can see the CMD field