Reputation: 569
I am mounting two volumes that way:
volumes:
- /home/username/videos:/var/www/symfony/ftp
- .docker/data/uploads/videos:/var/www/symfony/public/uploads/videos
Both folders on the host machine are on the same partition. If I run mv
on the host for files between /home/username/videos
and .docker/data/uploads/videos
, it's basically instant. But if I run mv
between var/www/symfony/ftp
and /var/www/symfony/public/uploads/videos
, it's painfully slow.
Basically, it seems like it's copying the file as if it was two completely different physical drives. The host machine is running Ubuntu 20.04, the Docker image Alpine 3.13.
Is this behavior expected? Any idea how I could improve that, if possible? (Other than just having both folder on the same volume)
Upvotes: 5
Views: 2335
Reputation: 263726
Linux implements these host mounts under the covers as two separate bind mounts into the container's mount namespace. And when you run a mv
, it checks if it can do a simple rename when the filesystem is the same. Unfortunately, when you go across bind mounts linux treats these as separate filesystems even when the underlying filesystem to the bind mount is the same.
Upvotes: 5
Reputation: 2731
If your host OS is using a different file system format on the local drive then the image does the mv command between volumes will have quite a bit of overhead.
Docker does its best to translate locally stored data to its internal encoding and back again.
e.g. from NTFS (local volume) to ext2 (image format) and back to NTFS (other local volume)
Docker tries to do this transparently without bothering you but on large files, this might be very noticeable.
In essence for the docker container these volumes are physically different drive :-)
Upvotes: 0