skip to Main Content

When I inspect a docker container , what does this path configuration mean and how is this value used?

        "Id": "xxx",
        "Created": "xxx",
        "Path": "orderer"

2

Answers


  1. When you docker container inspect <something>, the beginning of the output looks something like:

    [
        {
            "Id": "0e1ede44350e15fa2305f4b2dbfa0a5023de645bb535b05cac232e91069c4e7e",
            "Created": "2024-03-02T04:16:00.182581625Z",
            "Path": "/usr/local/bin/entrypoint",
            "Args": [
                "/sbin/init"
            ],
    
    • Id is the container id (you see this in the first column of docker container ps, and you can use it to reference a container instead of using the name)
    • Created is a timestamp that shows when the container was created
    • Path is the primary executable in the container. This is "the thing that is PID 1".
    • Args are the arguments provided to the executable described by Path

    If your container image has an ENTRYPOINT, Path will reflect the ENTRYPOINT script. Otherwise it will reflect the value of CMD — either the CMD entry from your Dockerfile or a command passed in on the docker run command line after the image name.

    Login or Signup to reply.
  2. Let’s figure this out empirically. See TLDR below for summary.

    Suppose that you run the following Python image:

    docker run -it python:3.11
    

    Looking at the top of the docker inspect output you’ll see:

    [
        {
            "Id": "6d701dc3ca52a52c87644529c4fbd49f9d3773ed863624f12d902ef5ae1a5fae",
            "Created": "2024-04-05T03:46:59.526713124Z",
            "Path": "python3",
            "Args": [],
        }
    ]
    

    The Path and Args fields need to be considered together. The above output indicates that the process launched in the container was python3 (with no further arguments).

    Now suppose I have another custom image that has

    CMD ["/bin/bash"]
    

    The corresponding docker inspect output is:

    [
        {
            "Id": "032559d7f5d6c4e13a72144939f640856707a35aef15678c7d36fd618045f2a9",
            "Created": "2024-04-05T03:49:29.523958197Z",
            "Path": "docker-entrypoint.sh",
            "Args": [
                "/bin/bash"
            ]
        }
    ]
    

    This tells us that the main command being run in the container is docker-entrypoint.sh /bin/bash. The script part of that command resolves to /usr/local/bin/docker-entrypoint.sh in the container and that script in turn will start a BASH shell when it has the /bin/bash argument.

    What about running another common container:

    docker run nginx
    
    [
        {
            "Id": "ca26054ce749298e8986a7e41a80887adb3bc3f6bbc25b3c89bc23c22cdb728b",
            "Created": "2024-04-05T03:57:23.880832236Z",
            "Path": "/docker-entrypoint.sh",
            "Args": [
                "nginx",
                "-g",
                "daemon off;"
            ]
        }
    ]
    

    Here the main command is /docker-entrypoint.sh nginx -g "daemon off;".

    Final example, a Dockerfile that ends like this:

    ENTRYPOINT ["java", "-jar", "/usr/local/lib/spring-boot-app.jar"]
    

    Here we can see where the Path comes from: it’s the first argument to ENTRYPOINT. The Args is populated by either (1) the remaining arguments to ENTRYPOINT or (2) all arguments to CMD.

    [
        {
            "Id": "7edf2de227e2641986e8c570cd7745544a1b35fb90a7dad85ab9ac9c830108a6",
            "Created": "2024-04-05T04:03:50.970668403Z",
            "Path": "java",
            "Args": [
                "-jar",
                "/usr/local/lib/spring-boot-app.jar"
            ]
        }
    ]
    

    TLDR

    The Path and Args fields in the docker inspect output specify the main process running in the container. The Path gives the name of the executable and the Args gives any arguments passed to the executable.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search