Bind mount not working

OS: Fedora Linux 36 (KDE) x86_64
Kernel: 6.2.15-100.fc36.x86_64
Docker version: 24.0.2, build cb74dfc
Docker Compose version: v2.18.1

I’m having an issue where the bound mount on a docker container just doesn’t work. None of the files in the host show up in the container and while everyone else on the team can easily build their containers I’m the only one left hanging.

A docker inspect shows the mount correctly:

        "Mounts": [
                "Type": "bind",
                "Source": "/var/www/html/ai-solutions/auditoria",
                "Destination": "/var/www/html",
                "Mode": "rw",
                "RW": true,
                "Propagation": "rprivate"

and yet, abolsutely no files show on the container.

The docker compose up --build -d command runs without any errors - images and volumes are created, I can access the containers shells, etc… - but still, no files in the mount and I honestly don’t know what else I can do.

Can anyone please help?


Just to be sure: you are aware that volumes are runtime configuration, and that they are not present during build time.

Since you are on a rhel based system, I can imagine that selinux might cause perfectly configured binds to now work as expected. With docker run you would use -v /var/www/html/ai-solutions/auditoria:/var/www/html:Z to modify the selinux labels (see here). It works the same way for the short volume syntax, but I have no idea how it needs to be configured for the long syntax.

Hi, thank you for the quick reply. SELinux isn’t running, I have it disabled:

> getenforce 

No idea then. If the source path on the host and the container path are correct, it should be at least listable inside the container, regardless whether the owner/group ip of the folders and files align with the user inside the container.

Exactly. And the paths are absolutely correct… I’ve double checked them a few times.

@galvao I’m on the same boat. Did you figure it out?

I’m pretty sure it’s a permissions issue. Some folders work, but others don’t.

The one that doesn’t work for me is the Homebrew folder. This is my setup:

    - /usr/local/Cellar/apache-spark/3.5.0/libexec:/spark
    - /usr/local/Cellar/apache-spark:/spark_test

If I do docker exec and ls -l /spark I get an empty directory, but surprisingly if I do ls -l /spark_test I get the 3.5.0 folder and the libexec folder inside it, but none of the other files that both of those directories contain on the host.

Well, check user:group for your folders on host. Are they the same or different? Did you start the image with a dedicated used? What’s the default user of your image/Dockerfile?

When you don’t have permission to access a folder, you can’t mount it, not to mention that if the Docker daemon is running as root I don’t see why you would have problem with permissions. Are you using Rootless Docker or maybe Docker Desktop? Did you install Docker as a snap package (could happen on Ubuntu)?

Homebrew is supported on Linux as well, but it is most likely to be used on macOS. If you run macOS, you run Docker DEsktop so you can’t just mount something from the Homebrew folder. You have to add that to the shared folders in the Settings of Docker Desktop, otherwise you just try to mount a folder from the virtual machine where it doesn’t exist and will be created as empty.

But I wouldn’t mount it at all, since that would just mount something built for macOS and wouldn’t work in a container. At least if I’m right and you use macOS.

1 Like

Thanks! I restarted Docker Desktop and it worked.