Bind mounted folder appears to be mounted as tmpfs on Ubuntu 22.04 and files are not visible on the host

Hey, I am facing similar issue. I want to persist data in mysql db using a a bind mount, the data appears inside the container at var/lib/mysql but it is not appearing in the dir in host. The data persists across container restarts somehow, but not across system restarts.

The docker inspect shows the bind mount correctly.

       "Mounts": [
            {
                "Type": "bind",
                "Source": "/var/www/emptycup/emptycup3d/data/mysql",
                "Destination": "/var/lib/mysql",
                "Mode": "rw",
                "RW": true,
                "Propagation": "rprivate"
            }
        ],

Are you using Rootless Docker or maybe Docker Desktop? Did you install Docker as a snap package (could happen on Ubuntu)?

I am using docker desktop in ubuntu 22.04, and no I didn’t install it as snap package.

1 interesting thing i noticed is that the /var/lib/mysql is shown as tmpfs even though the inspect shows bind mount.

> docker exec -it emptycup3d-db-1 sh -c "cat /proc/mounts | grep mysql"
tmpfs /etc/mysql/conf.d tmpfs rw,nosuid,nodev,noexec,relatime,mode=755 0 0
tmpfs /var/lib/mysql tmpfs rw,nosuid,nodev,noexec,relatime,mode=755 0 0

I have no idea why it would show tmpfs. I couldn’t reproduce it on macOS and I can’t start a Linux desktop now.

Isn’t the source folder on tmpfs?

Please, show the output of the following commands as well

docker info 
docker version

and hide any info in it you wouldn’t share like IP addresses or usernames.

I’m also going to move our posts into a new topic as the issue is unique enough even if the tmpfs is somehow normal on Linux. I’m not sure.

Here is the output for the commands you requested

> docker info 
docker version
Client: Docker Engine - Community
 Version:    27.5.1
 Context:    desktop-linux
 Debug Mode: false
 Plugins:
  ai: Ask Gordon - Docker Agent (Docker Inc.)
    Version:  v0.7.3
    Path:     /usr/lib/docker/cli-plugins/docker-ai
  buildx: Docker Buildx (Docker Inc.)
    Version:  v0.20.1-desktop.2
    Path:     /usr/lib/docker/cli-plugins/docker-buildx
  compose: Docker Compose (Docker Inc.)
    Version:  v2.32.4-desktop.1
    Path:     /usr/lib/docker/cli-plugins/docker-compose
  debug: Get a shell into any image or container (Docker Inc.)
    Version:  0.0.38
    Path:     /usr/lib/docker/cli-plugins/docker-debug
  desktop: Docker Desktop commands (Beta) (Docker Inc.)
    Version:  v0.1.4
    Path:     /usr/lib/docker/cli-plugins/docker-desktop
  dev: Docker Dev Environments (Docker Inc.)
    Version:  v0.1.2
    Path:     /usr/lib/docker/cli-plugins/docker-dev
  extension: Manages Docker extensions (Docker Inc.)
    Version:  v0.2.27
    Path:     /usr/lib/docker/cli-plugins/docker-extension
  feedback: Provide feedback, right in your terminal! (Docker Inc.)
    Version:  v1.0.5
    Path:     /usr/lib/docker/cli-plugins/docker-feedback
  init: Creates Docker-related starter files for your project (Docker Inc.)
    Version:  v1.4.0
    Path:     /usr/lib/docker/cli-plugins/docker-init
  sbom: View the packaged-based Software Bill Of Materials (SBOM) for an image (Anchore Inc.)
    Version:  0.6.0
    Path:     /usr/lib/docker/cli-plugins/docker-sbom
  scout: Docker Scout (Docker Inc.)
    Version:  v1.16.1
    Path:     /usr/lib/docker/cli-plugins/docker-scout

Server:
 Containers: 3
  Running: 3
  Paused: 0
  Stopped: 0
 Images: 7
 Server Version: 27.5.1
 Storage Driver: overlay2
  Backing Filesystem: extfs
  Supports d_type: true
  Using metacopy: false
  Native Overlay Diff: true
  userxattr: false
 Logging Driver: json-file
 Cgroup Driver: cgroupfs
 Cgroup Version: 2
 Plugins:
  Volume: local
  Network: bridge host ipvlan macvlan null overlay
  Log: awslogs fluentd gcplogs gelf journald json-file local splunk syslog
 CDI spec directories:
  /etc/cdi
  /var/run/cdi
 Swarm: inactive
 Runtimes: io.containerd.runc.v2 runc
 Default Runtime: runc
 Init Binary: docker-init
 containerd version: bcc810d6b9066471b0b6fa75f557a15a1cbf31bb
 runc version: v1.1.12-0-g51d5e946
 init version: de40ad0
 Security Options:
  seccomp
   Profile: unconfined
  cgroupns
 Kernel Version: 6.12.5-linuxkit
 Operating System: Docker Desktop
 OSType: linux
 Architecture: x86_64
 CPUs: 10
 Total Memory: 7.506GiB
 Name: docker-desktop
 ID: b04b1fcf-4e18-450b-add1-416c50ac70f4
 Docker Root Dir: /var/lib/docker
 Debug Mode: false
 HTTP Proxy: http.docker.internal:3128
 HTTPS Proxy: http.docker.internal:3128
 No Proxy: hubproxy.docker.internal
 Labels:
  com.docker.desktop.address=unix:///home/<user>/.docker/desktop/docker-cli.sock
 Experimental: false
 Insecure Registries:
  hubproxy.docker.internal:5555
  127.0.0.0/8
 Live Restore Enabled: false

WARNING: daemon is not using the default seccomp profile
Client: Docker Engine - Community
 Version:           27.5.1
 API version:       1.47
 Go version:        go1.22.11
 Git commit:        9f9e405
 Built:             Wed Jan 22 13:41:31 2025
 OS/Arch:           linux/amd64
 Context:           desktop-linux

Server: Docker Desktop 4.38.0 (181591)
 Engine:
  Version:          27.5.1
  API version:      1.47 (minimum version 1.24)
  Go version:       go1.22.11
  Git commit:       4c9b3b0
  Built:            Wed Jan 22 13:41:17 2025
  OS/Arch:          linux/amd64
  Experimental:     false
 containerd:
  Version:          1.7.25
  GitCommit:        bcc810d6b9066471b0b6fa75f557a15a1cbf31bb
 runc:
  Version:          1.1.12
  GitCommit:        v1.1.12-0-g51d5e946
 docker-init:
  Version:          0.19.0
  GitCommit:        de40ad0

Can you reproduce it with other images? Try this command, please:

docker run --rm -it -v $PWD:/app bash cat /proc/mounts | grep app

I tried on Ubuntu 22.04 with the same Docker DEsktop version (4.38.0)
And you should get this:

/run/host_mark/home /app fakeowner rw,nosuid,nodev,relatime,fakeowner 0 0

the source can be different if you don’t run it in your home dir.

And what is the filesystem type on your host under /var/www/emptycup/emptycup3d/data/mysql?

Th output for bash image from /home

> docker run --rm -it -v $PWD:/app bash cat /proc/mounts | grep app
/run/host_mark/home /app fakeowner rw,nosuid,nodev,relatime,fakeowner 0 0

Also the file system type for /var/www/emptycup/emptycup3d/data/mysql is ext4, and I am amusing that the mysql dir in data would be created by the mysql image, but it doesn’t create it, and even if I create it and chown the dir to user 999:root, (999 because mysql user is 999 by default), the container throws the following error:

2025-02-19 18:18:25 chown: changing ownership of '/var/lib/mysql/': Permission denied
2025-02-19 18:18:25 chown: changing ownership of '/var/lib/mysql': Permission denied
2025-02-19 18:18:38 chown: changing ownership of '/var/lib/mysql/': Permission denied
2025-02-19 18:18:38 chown: changing ownership of '/var/lib/mysql': Permission denied

Can you show how you create the MySQL container and using which image? Please, share a compose file if you have.

Since your folder is mounted from tmpfs, it doesn’t matter what you do on the host. It won’t be used.

Actually, I double checked, If I create the dir and chown it(either to 999:root or root:root) it shows permission error:

2025-02-19 18:18:25 chown: changing ownership of '/var/lib/mysql/': Permission denied
2025-02-19 18:18:25 chown: changing ownership of '/var/lib/mysql': Permission denied
2025-02-19 18:18:38 chown: changing ownership of '/var/lib/mysql/': Permission denied
2025-02-19 18:18:38 chown: changing ownership of '/var/lib/mysql': Permission denied

And here is the section of compose file for that image:

  db:
    image: mysql:5.7
    restart: always
    environment:
      MYSQL_ROOT_PASSWORD: <pass>
      MYSQL_DATABASE: <db>
    ports:
      - "3306:3306"
    volumes:
      - /var/www/emptycup/emptycup3d/data/mysql:/var/lib/mysql

The storage type of source folder on host is ext4

I’ve the same problem as Manan. If I just run sudo docker run -v /sql:/sql -it ubuntu bash
I get an tmpfs mount which doesn’t belong to the host directory. Here is the mount list of the running container:

# mount -l
overlay on / type overlay (rw,relatime,lowerdir=/var/snap/docker/common/var-lib-docker/overlay2/l/N2G6IHL6NQU4XWGK7CREEUFCNJ:/var/snap/docker/common/var-lib-docker/overlay2/l/7D46QPOYVA3OYOTG7IOBKAY7GJ,upperdir=/var/snap/docker/common/var-lib-docker/overlay2/fc15bd4c45266f548f3ca2198552f214ad43f82fc9c3aac8722c68f573035ad0/diff,workdir=/var/snap/docker/common/var-lib-docker/overlay2/fc15bd4c45266f548f3ca2198552f214ad43f82fc9c3aac8722c68f573035ad0/work)
proc on /proc type proc (rw,nosuid,nodev,noexec,relatime)
tmpfs on /dev type tmpfs (rw,nosuid,size=65536k,mode=755,inode64)
devpts on /dev/pts type devpts (rw,nosuid,noexec,relatime,gid=5,mode=620,ptmxmode=666)
sysfs on /sys type sysfs (ro,nosuid,nodev,noexec,relatime)
cgroup on /sys/fs/cgroup type cgroup2 (ro,nosuid,nodev,noexec,relatime,nsdelegate,memory_recursiveprot)
mqueue on /dev/mqueue type mqueue (rw,nosuid,nodev,noexec,relatime)
shm on /dev/shm type tmpfs (rw,nosuid,nodev,noexec,relatime,size=65536k,inode64)
none on /sql type tmpfs (rw,relatime,inode64) <----- HERE IS THE PROBLEM
/dev/mapper/ubuntu--vg-ubuntu--lv on /etc/resolv.conf type ext4 (rw,relatime)
/dev/mapper/ubuntu--vg-ubuntu--lv on /etc/hostname type ext4 (rw,relatime)
/dev/mapper/ubuntu--vg-ubuntu--lv on /etc/hosts type ext4 (rw,relatime)
devpts on /dev/console type devpts (rw,nosuid,noexec,relatime,gid=5,mode=620,ptmxmode=666)
proc on /proc/bus type proc (ro,nosuid,nodev,noexec,relatime)
proc on /proc/fs type proc (ro,nosuid,nodev,noexec,relatime)
proc on /proc/irq type proc (ro,nosuid,nodev,noexec,relatime)
proc on /proc/sys type proc (ro,nosuid,nodev,noexec,relatime)
proc on /proc/sysrq-trigger type proc (ro,nosuid,nodev,noexec,relatime)
tmpfs on /proc/asound type tmpfs (ro,relatime,inode64)
tmpfs on /proc/acpi type tmpfs (ro,relatime,inode64)
tmpfs on /proc/kcore type tmpfs (rw,nosuid,size=65536k,mode=755,inode64)
tmpfs on /proc/keys type tmpfs (rw,nosuid,size=65536k,mode=755,inode64)
tmpfs on /proc/timer_list type tmpfs (rw,nosuid,size=65536k,mode=755,inode64)
tmpfs on /proc/scsi type tmpfs (ro,relatime,inode64)
tmpfs on /sys/firmware type tmpfs (ro,relatime,inode64)
tmpfs on /sys/devices/virtual/powercap type tmpfs (ro,relatime,inode64)

as you can see, it’s a tmpfs not mounted from host.

If I run a totally different image with the same mount option, I can access the data from the previously stopped container, but the data is not at host storage and it’s gone if I restart the host.

The owner of the host directory is root and it have an chmod of 777.

While fiddle around with this problem I tried multiple -v variants (relative, absolute, other folders) and at some point it worked once. Then I had to restart the host and run the same command as before and get the problem back :confounded:

So I would appreciate any advice.

I only turn on the Linux machine when I have very little time to try Docker Desktop on it, so if it is something happening only on Linux, it is difficult for me to reproduce it. It is very strange though. The only difference I see between the mysql container’s folder and the test container’s folder is that the MySQL image has an anonymous volume defined in it and that I shared a docker run command not a compose file.

  • So we can try to test what happens if you try another image which has an anonymous volume definition and mount something from the host to that folder.
  • The other thing you can try is converting my recommended docker run command to compose and see if it makes a difference.

Since I don’t know what image has anonymous volume definition, you can try to create a simple Dockerfile

FROM bash

VOLUME /app

Build it

docker build . -t localhost/test

Run it using docker run

docker run -it -v $PWD:/app localhost/test cat /proc/mounts | grep app

Create a compose file:

services:
  test:
    image: localhost/test
    command:
      - cat
      - /proc/mounts
    volumes:
      - .:/app

Run it using docker compose up

docker compose up | grep app

and docker compose run

docker compose run --rm test | grep app

Except you have Docker installed as a Snap package which is not recommended

But you can try my recommended commands too.

If you really have the same problem, then this is not even strictly related to Docker Desktop.

It would still be great if you could try it with Docker CE as well as recommended in the installation guide in the official documentation:

If it is Ubuntu, then this is it: Ubuntu | Docker Docs

Actually @07manan, could you please share the first line of the cat /proc/mounts command in the container too? Since you have Docker Desktop, I’m not sure what I’m looking for yet, but I’m curious.

Except you have Docker installed as a Snap package which is not recommended

:man_facepalming:
sry for that. I’ve set the checkbox for docker at the install wizard of ubuntu. While fiddling around, I already followed the mentioned install docs from docker, including the uninstall step. So I assumed the installed version from ubuntu setup is removed, but I haven’t validated it and never thought about snap.
So good catch :slight_smile:
Now I’ve started all over again without checking the docker checkbox at setup and installed docker on an clean ubuntu install.
What should I say. No problems anymore. Thanks for your help.

I hope Manan could find the cause of his problem too. :crossed_fingers: