Bind mount files from container not showing to host

I’m trying to get files from my container to my host by using bind mount, but the existing files from container side are not showing on my host side.

This is the empty directory on my host which I’m mounting:

/tmp/myapp

This is the container side of the mount:

/app

“/app” directory on the container already has files in it at the creation time of the bind mount and those are the files I want to receive on the host side of the volume, but the host side shows empty. Although if inside the container I move new files in the /app directory, they would show on the host side. So I’m confused why it doesn’t work on the existing files or is this really the way it’s supposed to work?

This is how the mount looks with docker inspect:

"Mounts": [
            {
                "Type": "bind",
                "Source": "/tmp/myapp",
                "Destination": "/app",
                "Mode": "",
                "RW": true,
                "Propagation": "shared"
            }

You are on the wrong track… it doesn’t work like that, regardless of the mount propagation (which is about propagating information about child mounts within the mount).

If you bind a host folder into a container folder, the container folder will be eclipsed with the content of the host folder. So if the host folder was/is empty, the container will see an empty folder.

It literally does the same as mount --bind /src /target. Please play around with it on your host to understand how it works (don’t forget to unmount the binds after testing!).

I recommend reading my blogpost about volumes: Everything about Docker volumes - DEV Community
especially the Custom volume path section.

In short, only volumes will copy the content from the container to the host when the host folder is still empty. Setting a custom souce path could help, but you probably don’t want just looking at the files, but also edit them, which you usually shouldn’t.