Docker run mounting volumes but docker inspect has volumes as null

My issue is regarding a docker run command I have created which is running to completion and creating the service however it has mount/volume issues. I am running the following command:

docker run -d --restart=unless-stopped --log-driver json-file --log-opt max-file="3" --log-opt max-size="15m" -m 2.875g --cpu-shares=230 --ulimit nofile=262144:262144 --ulimit memlock=-1:-1 --group-add="elasticsearch"  --user="elasticsearch" --net="host" -p 192.168.56.103:9200:9200 -p 192.168.56.103:9300:9300 -v /var/qpackage/elasticsearch/repo:/usr/share/elasticsearch/repo:rw -v /etc/qpackage/elasticsearch/conf/elasticsearch.yml:/usr/share/elasticsearch/config/elasticsearch.yml:rw -v /var/qpackage/elasticsearch/data:/usr/share/elasticsearch/data:rw -v /etc/qpackage/elasticsearch/conf/jvm.options:/usr/share/elasticsearch/config/jvm.options:rw -e "SERVICE_9200_NAME=elasticsearch" -e "SERVICE_9300_NAME=elasticsearch-node" --name elasticsearch-1_log_elasticsearch elasticsearch

And it seems to run perfectly fine. When I do a docker inspect however I notice whilst the volumes are I have placed in the command are being mounted and the binds correct the inspect also shows me that Volumes are null. This is incorrect behaviour. The volumes are supposed to shown.

Current Result

"Volumes": null,

Expected Result

"Volumes": {
                "/usr/share/elasticsearch/config/elasticsearch.yml": {},
                "/usr/share/elasticsearch/config/jvm.options": {},
                "/usr/share/elasticsearch/data": {},
                "/usr/share/elasticsearch/repo": {}
            },

What could I be doing wrong?

Full Docker Inspect

[root@localhost tmp]# docker inspect elasticsearch-1_log_elasticsearch
[
    {
        "Id": "be782ca624a468e30dd8c79748ef5406781134c3b6f93450b3b3f425af701301",
        "Created": "2019-11-18T21:48:34.243146943Z",
        "Path": "/usr/local/bin/docker-entrypoint.sh",
        "Args": [
            "eswrapper"
        ],
        "State": {
            "Status": "running",
            "Running": true,
            "Paused": false,
            "Restarting": false,
            "OOMKilled": false,
            "Dead": false,
            "Pid": 18111,
            "ExitCode": 0,
            "Error": "",
            "StartedAt": "2019-11-18T21:48:34.645908733Z",
            "FinishedAt": "0001-01-01T00:00:00Z"
        },
        "Image": "sha256:6e4f392617213267be91ed63bcd83a425425ed825cf0ab1f346d55375e48d91b",
        "ResolvConfPath": "/var/qpackage/docker/containers/be782ca624a468e30dd8c79748ef5406781134c3b6f93450b3b3f425af701301/resolv.conf",
        "HostnamePath": "/var/qpackage/docker/containers/be782ca624a468e30dd8c79748ef5406781134c3b6f93450b3b3f425af701301/hostname",
        "HostsPath": "/var/qpackage/docker/containers/be782ca624a468e30dd8c79748ef5406781134c3b6f93450b3b3f425af701301/hosts",
        "LogPath": "/var/qpackage/docker/containers/be782ca624a468e30dd8c79748ef5406781134c3b6f93450b3b3f425af701301/be782ca624a468e30dd8c79748ef5406781134c3b6f93450b3b3f425af701301-json.log",
        "Name": "/elasticsearch-1_log_elasticsearch",
        "RestartCount": 0,
        "Driver": "overlay2",
        "Platform": "linux",
        "MountLabel": "",
        "ProcessLabel": "",
        "AppArmorProfile": "",
        "ExecIDs": null,
        "HostConfig": {
            "Binds": [
                "/etc/qpackage/elasticsearch/conf/elasticsearch.yml:/usr/share/elasticsearch/config/elasticsearch.yml",
                "/var/qpackage/elasticsearch/data:/usr/share/elasticsearch/data",
                "/etc/qpackage/elasticsearch/conf/jvm.options:/usr/share/elasticsearch/config/jvm.options",
                "/var/qpackage/elasticsearch/repo:/usr/share/elasticsearch/repo"
            ],
            "ContainerIDFile": "",
            "LogConfig": {
                "Type": "json-file",
                "Config": {
                    "max-file": "3",
                    "max-size": "15m"
                }
            },
            "NetworkMode": "host",
            "PortBindings": {
                "9200/tcp": [
                    {
                        "HostIp": "192.168.56.103",
                        "HostPort": "9200"
                    }
                ],
                "9300/tcp": [
                    {
                        "HostIp": "192.168.56.103",
                        "HostPort": "9300"
                    }
                ]
            },
            "RestartPolicy": {
                "Name": "unless-stopped",
                "MaximumRetryCount": 0
            },
            "AutoRemove": false,
            "VolumeDriver": "",
            "VolumesFrom": null,
            "CapAdd": null,
            "CapDrop": null,
            "Dns": [],
            "DnsOptions": [],
            "DnsSearch": [],
            "ExtraHosts": null,
            "GroupAdd": [
                "elasticsearch"
            ],
            "IpcMode": "shareable",
            "Cgroup": "",
            "Links": null,
            "OomScoreAdj": 0,
            "PidMode": "",
            "Privileged": false,
            "PublishAllPorts": false,
            "ReadonlyRootfs": false,
            "SecurityOpt": null,
            "UTSMode": "",
            "UsernsMode": "",
            "ShmSize": 67108864,
            "Runtime": "runc",
            "ConsoleSize": [
                0,
                0
            ],
            "Isolation": "",
            "CpuShares": 230,
            "Memory": 3087007744,
            "NanoCpus": 0,
            "CgroupParent": "",
            "BlkioWeight": 0,
            "BlkioWeightDevice": [],
            "BlkioDeviceReadBps": null,
            "BlkioDeviceWriteBps": null,
            "BlkioDeviceReadIOps": null,
            "BlkioDeviceWriteIOps": null,
            "CpuPeriod": 0,
            "CpuQuota": 0,
            "CpuRealtimePeriod": 0,
            "CpuRealtimeRuntime": 0,
            "CpusetCpus": "",
            "CpusetMems": "",
            "Devices": [],
            "DeviceCgroupRules": null,
            "DiskQuota": 0,
            "KernelMemory": 0,
            "MemoryReservation": 0,
            "MemorySwap": 6174015488,
            "MemorySwappiness": null,
            "OomKillDisable": false,
            "PidsLimit": 0,
            "Ulimits": [
                {
                    "Name": "nofile",
                    "Hard": 262144,
                    "Soft": 262144
                },
                {
                    "Name": "memlock",
                    "Hard": -1,
                    "Soft": -1
                }
            ],
            "CpuCount": 0,
            "CpuPercent": 0,
            "IOMaximumIOps": 0,
            "IOMaximumBandwidth": 0,
            "MaskedPaths": [
                "/proc/asound",
                "/proc/acpi",
                "/proc/kcore",
                "/proc/keys",
                "/proc/latency_stats",
                "/proc/timer_list",
                "/proc/timer_stats",
                "/proc/sched_debug",
                "/proc/scsi",
                "/sys/firmware"
            ],
            "ReadonlyPaths": [
                "/proc/bus",
                "/proc/fs",
                "/proc/irq",
                "/proc/sys",
                "/proc/sysrq-trigger"
            ]
        },
        "GraphDriver": {
            "Data": {
                "LowerDir": "/var/qpackage/docker/overlay2/f23fc0453e6ef6309612864951ffa3d279dd1197a9f2cb5e27fb7884c16eba69-init/diff:/var/qpackage/docker/overlay2/cc295c456ff0d7a6e33e62578915d4b2dfaec5778e3c7c95a15862333f2ddc87/diff:/var/qpackage/docker/overlay2/baa3e9c814aa237120bbd1668a8dfec75444e3d44ec46afdaf818b03d0584bb6/diff:/var/qpackage/docker/overlay2/ac48075afe8ae211844285573419bc9e08b92b89877deca5b10eed7f071fd43c/diff:/var/qpackage/docker/overlay2/b1395bb3de16587b201eceaa1468951c1224fcd37d3e49ff012954fa0e621836/diff:/var/qpackage/docker/overlay2/a2ac251b148df5aba19addea36ecd85b7b45a5590740684ae928586f55a93fdc/diff:/var/qpackage/docker/overlay2/0cb5d6a8739367e5eab2b071f5ec3f4cb6e4d62b4d94a4919635ec05e7a6198f/diff:/var/qpackage/docker/overlay2/67657868ee478d3cb47093c67d1824eb873e2628840486bb63aef7eee29652bd/diff:/var/qpackage/docker/overlay2/108ed1526882b849cf3991c8177b7389e84da4b9a48828f43b08351b6c69ddf0/diff",
                "MergedDir": "/var/qpackage/docker/overlay2/f23fc0453e6ef6309612864951ffa3d279dd1197a9f2cb5e27fb7884c16eba69/merged",
                "UpperDir": "/var/qpackage/docker/overlay2/f23fc0453e6ef6309612864951ffa3d279dd1197a9f2cb5e27fb7884c16eba69/diff",
                "WorkDir": "/var/qpackage/docker/overlay2/f23fc0453e6ef6309612864951ffa3d279dd1197a9f2cb5e27fb7884c16eba69/work"
            },
            "Name": "overlay2"
        },
        "Mounts": [
            {
                "Type": "bind",
                "Source": "/etc/qpackage/elasticsearch/conf/elasticsearch.yml",
                "Destination": "/usr/share/elasticsearch/config/elasticsearch.yml",
                "Mode": "",
                "RW": true,
                "Propagation": "rprivate"
            },
            {
                "Type": "bind",
                "Source": "/var/qpackage/elasticsearch/data",
                "Destination": "/usr/share/elasticsearch/data",
                "Mode": "",
                "RW": true,
                "Propagation": "rprivate"
            },
            {
                "Type": "bind",
                "Source": "/etc/qpackage/elasticsearch/conf/jvm.options",
                "Destination": "/usr/share/elasticsearch/config/jvm.options",
                "Mode": "",
                "RW": true,
                "Propagation": "rprivate"
            },
            {
                "Type": "bind",
                "Source": "/var/qpackage/elasticsearch/repo",
                "Destination": "/usr/share/elasticsearch/repo",
                "Mode": "",
                "RW": true,
                "Propagation": "rprivate"
            }
        ],
        "Config": {
            "Hostname": "localhost.localdomain",
            "Domainname": "",
            "User": "elasticsearch",
            "AttachStdin": false,
            "AttachStdout": false,
            "AttachStderr": false,
            "ExposedPorts": {
                "9200/tcp": {},
                "9300/tcp": {}
            },
            "Tty": false,
            "OpenStdin": false,
            "StdinOnce": false,
            "Env": [
                "SERVICE_9200_NAME=elasticsearch",
                "SERVICE_9300_NAME=elasticsearch-node",
                "PATH=/usr/share/elasticsearch/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
                "ELASTIC_CONTAINER=true"
            ],
            "Cmd": [
                "eswrapper"
            ],
            "ArgsEscaped": true,
            "Image": "cp-elasticsearch:7.1.ox",
            "Volumes": null,
            "WorkingDir": "/usr/share/elasticsearch",
            "Entrypoint": [
                "/usr/local/bin/docker-entrypoint.sh"
            ],
            "OnBuild": null,
            "Labels": {
                "license": "Elastic License",
                "org.label-schema.build-date": "20190305",
                "org.label-schema.license": "GPLv2",
                "org.label-schema.name": "elasticsearch",
                "org.label-schema.schema-version": "1.0",
                "org.label-schema.url": "https://www.elastic.co/products/elasticsearch",
                "org.label-schema.vcs-url": "https://github.com/elastic/elasticsearch",
                "org.label-schema.vendor": "Elastic",
                "org.label-schema.version": "7.1.0"
            }
        },
        "NetworkSettings": {
            "Bridge": "",
            "SandboxID": "087bbb8b4469e2a5ac35aee69b62c7e8db8eb6bc16acf529d437f4777586cbac",
            "HairpinMode": false,
            "LinkLocalIPv6Address": "",
            "LinkLocalIPv6PrefixLen": 0,
            "Ports": {},
            "SandboxKey": "/var/run/docker/netns/default",
            "SecondaryIPAddresses": null,
            "SecondaryIPv6Addresses": null,
            "EndpointID": "",
            "Gateway": "",
            "GlobalIPv6Address": "",
            "GlobalIPv6PrefixLen": 0,
            "IPAddress": "",
            "IPPrefixLen": 0,
            "IPv6Gateway": "",
            "MacAddress": "",
            "Networks": {
                "host": {
                    "IPAMConfig": null,
                    "Links": null,
                    "Aliases": null,
                    "NetworkID": "047831b94cd687f5e144568ac52925897a8b2f5ee21c9af7286c0afe39b3ee03",
                    "EndpointID": "1a2e3b823fc5d28b4ddb4ccda9c005fff2f15d439d7f65ec27fbe2587f5395d1",
                    "Gateway": "",
                    "IPAddress": "",
                    "IPPrefixLen": 0,
                    "IPv6Gateway": "",
                    "GlobalIPv6Address": "",
                    "GlobalIPv6PrefixLen": 0,
                    "MacAddress": "",
                    "DriverOpts": null
                }
            }
        }
    }
]

Your “volumes” are in fact mount-binds. I am afraid your expectation is based on an incomplete understanding of volumes.

List of mounted volumes: docker inspect e9baf44ea24b | jq '.[].HostConfig.Mounts'
List of used binds: docker inspect e9baf44ea24b | jq '.[].HostConfig.Binds'
List of volumes declared in Dockerfile: docker inspect e9baf44ea24b | jq '.[].Config.Volumes'

Replace the containerid e9baf44ea24b with one of your choice.

Can you please correct my understanding then? Given the run command above, how would I change it so the volumes are added as I would like?
I have this configuration using an ansible deployer and also using the run command. The ansible deployer is correctly adding the volumes but the run command is not doing so with the exact same parameters. The installation is completing etc and elastic is running but not performing as we would like because the volumes haven’t been added.

Did you by any chance test the ouput of the examples? (of course with the containerid of your container)

I assume your “Full Docker Inspect” is the example of the container that you suspect to work wrong. The snipped lists all mounted binds and volumes underneath .Mouts. All four binds used in the docker run statement are present:

For my understanding “Volumes”: will be static for an image - its values originate from the VOLUMES delared in the Dockerfile used to build the image.

Thus, I am unclear on what actualy is not working for your.

@meyay The expected result shown above is from an ansible deployment of the docker run command shown above using the docker_container method in ansible(see here). It doesn’t build a new image. Running the following command within it when I run inspect the volumes section (not mount) of the inspect shows the expected as result as above.

- name: Install elasticsearch docker
      docker_container:
          name: "{{ id }}"
          state: started
          log_driver: json-file
          user: elasticsearch
          groups: elasticsearch
          log_options:
            max-size: 15m
            max-file: "3"
          image: "{{ elasticsearch }}"
          volumes:
            - "{{ elasticsearch_conf_dir }}/elasticsearch.yml:/usr/share/elasticsearch/config/elasticsearch.yml"
            - "{{ elasticsearch_data_dir }}:/usr/share/elasticsearch/data"
            - "{{ elasticsearch_repo_dir }}:/usr/share/elasticsearch/repo"
          network_mode: "{{ elasticsearch_network }}"
          restart_policy: unless-stopped
          cpu_shares: "{{ elasticsearch_cpu_shares }}"
          memory: "{{ elasticsearch_memory_limit }}"
          memory_swap: "{{ elasticsearch_memory_swap }}"
          ports:
            - "{{ elasticsearch_listen_address }}:{{ elasticsearch_listen_port }}:9200"
            - "{{ elasticsearch_listen_address }}:{{ elasticsearch_listen_port_nodes }}:9300"
          env:
            SERVICE_9200_NAME: "{{ service_name }}"
            SERVICE_9300_NAME: "{{ service_name }}-node"
            ES_JAVA_OPTS: "{{ elasticsearch_java_opts }}"
          ulimits:
            - "memlock:-1:-1"
            - "nofile:262144:262144"

The docker run command I have provided does the same thing but when I run inspect the volumes section in the inspect is an empty array even though the binds are showing in the mount section. I don’t have a docker file for both scenarios because at no point am I building an image. Its imperative that the docker run we generate be able to replicate exactly the same inspect result as the ansible deployment. We have tested and seen little difference but we don’t want to have corner cases we haven’t tested that fail because of difference.

I never wrote that you would build an image, did i? I wrote that the information in the “volumes” section was populated from the declared in the Dockerfile used to build the image - the one pushed into the repo by the maintainer or the image, You just pulled and used it - including its metadata.

I still am unclear why the behavior of a third party tool is your reference and the behavior of the Docker Engine seems wrong to you - shouldn’t it be the other way arround? I mean, why does a third party tool change metadata differently that the docker engine itself does when docker run is used?

Heck, I still do not understand which pain you experience, why it is a pain and why you need to resolve it. If the mounts do work, which you wrote they do… where is the problem!!!