Red5d / docker-autocompose

Generate a docker-compose yaml definition from a running container
1.76k stars 197 forks source link

Shared mounts are not exported properly #58

Open peterbuga opened 1 year ago

peterbuga commented 1 year ago

An original container definition that has a shared mount ex: /host/folder:/container/folder:shared gives an output /host/folder:/container/folder

Red5d commented 1 year ago

@peterbuga can you provide a link to docker-compose documentation that references ":shared" as a mode for volume definition? I looked, but am unable to find a reference to that.

peterbuga commented 1 year ago

@Red5d thanks for looking into this, here's the reference https://docs.docker.com/storage/bind-mounts/#configure-bind-propagation

here's an example too on how I use this: using this image https://hub.docker.com/r/mumiehub/rclone-mount/ I basically mount an external-folder inside the container and by using :shared to the mount, the mounted folder inside container are accessible to the host (check also the example in the image documentation) ps: i use the same principle with mergerfs or other smb mounts

services:
  rclone:
    container_name: "rclone"
    devices:
      - "/dev/fuse:/dev/fuse"
    entrypoint:
      - "/init"
    environment:
      - ...
      - ...
    image: "mumiehub/rclone-mount"
    ipc: "private"
    logging:
      driver: "json-file"
      options: {}
    restart: "unless-stopped"
    security_opt:
      - "apparmor:unconfined"
    volumes:
      - "rclone:/config"
      - "/mnt/rclone:/mounts/rclone" <-- missing `:shared` here

hope it makes some sense now, cheers!

Red5d commented 1 year ago

Ok, cool. Can you provide the output of "docker inspect" for a running container that's set up like that?

peterbuga commented 1 year ago

@Red5d I edited some of the important details but this should suffice I think

it's a different image used in this example https://hub.docker.com/r/mumiehub/smb-mount (a simpler one IMO) but the reported problem it's the same

[
    {
        "Id": "[container-id]",
        "Created": "2023-02-09T08:04:32.562435577Z",
        "Path": "/init",
        "Args": [],
        "State": {
            "Status": "running",
            "Running": true,
            "Paused": false,
            "Restarting": false,
            "OOMKilled": false,
            "Dead": false,
            "Pid": 7360,
            "ExitCode": 0,
            "Error": "",
            "StartedAt": "2023-04-22T07:26:01.85491629Z",
            "FinishedAt": "2023-04-22T07:18:35.076891998Z"
        },
        "Image": "sha256:a5263dd94b67d2856688163a117bf81b238f2db1362229d6e76b0f7a1d80e413",
        "ResolvConfPath": "/var/lib/docker/containers/[container-id]/resolv.conf",
        "HostnamePath": "/var/lib/docker/containers/[container-id]/hostname",
        "HostsPath": "/var/lib/docker/containers/[container-id]/hosts",
        "LogPath": "/var/lib/docker/containers/[container-id]/[container-id]-json.log",
        "Name": "/smb_mount",
        "RestartCount": 0,
        "Driver": "overlay2",
        "Platform": "linux",
        "MountLabel": "",
        "ProcessLabel": "",
        "AppArmorProfile": "unconfined",
        "ExecIDs": null,
        "HostConfig": {
            "Binds": [
                "/mnt/hostsmb:/mnt/smb:shared"
            ],
            "ContainerIDFile": "",
            "LogConfig": {
                "Type": "json-file",
                "Config": {}
            },
            "NetworkMode": "localnet",
            "PortBindings": {},
            "RestartPolicy": {
                "Name": "unless-stopped",
                "MaximumRetryCount": 0
            },
            "AutoRemove": false,
            "VolumeDriver": "",
            "VolumesFrom": [],
            "ConsoleSize": [
                0,
                0
            ],
            "CapAdd": [
                "SYS_ADMIN",
                "DAC_READ_SEARCH"
            ],
            "CapDrop": null,
            "CgroupnsMode": "host",
            "Dns": [],
            "DnsOptions": [],
            "DnsSearch": [],
            "ExtraHosts": null,
            "GroupAdd": null,
            "IpcMode": "private",
            "Cgroup": "",
            "Links": null,
            "OomScoreAdj": 0,
            "PidMode": "",
            "Privileged": false,
            "PublishAllPorts": false,
            "ReadonlyRootfs": false,
            "SecurityOpt": [
                "apparmor:unconfined"
            ],
            "UTSMode": "",
            "UsernsMode": "",
            "ShmSize": 67108864,
            "Runtime": "runc",
            "Isolation": "",
            "CpuShares": 0,
            "Memory": 0,
            "NanoCpus": 0,
            "CgroupParent": "",
            "BlkioWeight": 0,
            "BlkioWeightDevice": null,
            "BlkioDeviceReadBps": null,
            "BlkioDeviceWriteBps": null,
            "BlkioDeviceReadIOps": null,
            "BlkioDeviceWriteIOps": null,
            "CpuPeriod": 0,
            "CpuQuota": 0,
            "CpuRealtimePeriod": 0,
            "CpuRealtimeRuntime": 0,
            "CpusetCpus": "",
            "CpusetMems": "",
            "Devices": null,
            "DeviceCgroupRules": null,
            "DeviceRequests": null,
            "MemoryReservation": 0,
            "MemorySwap": 0,
            "MemorySwappiness": null,
            "OomKillDisable": false,
            "PidsLimit": null,
            "Ulimits": null,
            "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/lib/docker/overlay2/e5578bdeee5cc0914a4f9913d4f8e7625313f5045210b5a77786bba4ecbb8eb9-init/diff:/var/lib/docker/overlay2/6e155261473e32c370a3761f1a150132a584eed5fbbef509299cdec2c04fa779/diff:/var/lib/docker/overlay2/c68cf5cfd1fb19f5405ef2a1e9935d837aa77c6c715ce892a25ee4daadc84125/diff:/var/lib/docker/overlay2/ab9538be86d0b6687675402ead127d72aca6c9e47490a7c0d3a7b3574202ccd0/diff",
                "MergedDir": "/var/lib/docker/overlay2/e5578bdeee5cc0914a4f9913d4f8e7625313f5045210b5a77786bba4ecbb8eb9/merged",
                "UpperDir": "/var/lib/docker/overlay2/e5578bdeee5cc0914a4f9913d4f8e7625313f5045210b5a77786bba4ecbb8eb9/diff",
                "WorkDir": "/var/lib/docker/overlay2/e5578bdeee5cc0914a4f9913d4f8e7625313f5045210b5a77786bba4ecbb8eb9/work"
            },
            "Name": "overlay2"
        },
        "Mounts": [
            {
                "Type": "bind",
                "Source": "/mnt/hostsmb",
                "Destination": "/mnt/smb",
                "Mode": "shared",
                "RW": true,
                "Propagation": "shared"
            }
        ],
        "Config": {
            "Hostname": "smb_mount",
            "Domainname": "",
            "User": "",
            "AttachStdin": false,
            "AttachStdout": false,
            "AttachStderr": false,
            "Tty": false,
            "OpenStdin": false,
            "StdinOnce": false,
            "Env": [
                "REDACTED=values",
            ],
            "Cmd": null,
            "Image": "mumiehub/smb-mount",
            "Volumes": {
                "/mnt/smb": {}
            },
            "WorkingDir": "",
            "Entrypoint": [
                "/init"
            ],
            "OnBuild": null,
            "Labels": {
                "redacted": "values"
            }
        },
        "NetworkSettings": {
            "Bridge": "",
            "SandboxID": "ce343a715b70c14352d035ff526704d1d8f43793004a8af486048b7c92a796e3",
            "HairpinMode": false,
            "LinkLocalIPv6Address": "",
            "LinkLocalIPv6PrefixLen": 0,
            "Ports": {},
            "SandboxKey": "/var/run/docker/netns/ce343a715b70",
            "SecondaryIPAddresses": null,
            "SecondaryIPv6Addresses": null,
            "EndpointID": "",
            "Gateway": "",
            "GlobalIPv6Address": "",
            "GlobalIPv6PrefixLen": 0,
            "IPAddress": "",
            "IPPrefixLen": 0,
            "IPv6Gateway": "",
            "MacAddress": "",
            "Networks": {
                "localnet": {
                    "IPAMConfig": null,
                    "Links": null,
                    "Aliases": [
                        "53aa730eafb4",
                        "smb_mount"
                    ],
                    "NetworkID": "46d88df4c18cdd7c6d75816d2835794e1e86c8328e973da0b36462841027ae80",
                    "EndpointID": "08c95e038913b2f5d74e5059cf08f9376d0fc9e66420f8ad1f2716814042dbb8",
                    "Gateway": "172.28.0.254",
                    "IPAddress": "172.28.0.10",
                    "IPPrefixLen": 16,
                    "IPv6Gateway": "",
                    "GlobalIPv6Address": "",
                    "GlobalIPv6PrefixLen": 0,
                    "MacAddress": "02:42:ac:1c:00:0a",
                    "DriverOpts": null
                }
            }
        }
    }
]