docker/compose

[BUG] Bind mount file to file makes a file to directory

Grasume opened this issue · 1 comments

Description

Working with someone in Discord and he noticed this issue. Was able to reproduce and cant find in the docs anymore where it specified file to file or folder to folder.

But when performing a simple bind mount like so volumes: - ./test/file.text:/test/file.text
the file.text becomes a diretory
if i just do the directory
volumes: - ./test/:/test/
is this supposed to be happening ? Did the ability to perform file to file bind mounts get removed ?

Steps To Reproduce

repo with simple folder structure https://github.com/Grasume/docker_example/tree/production/docker-compose-bindmount
docker compose up - d

docker-compose exec -it test sh

ls -l /test/ total 4 drwxr-xr-x 2 root root 4096 Nov 28 00:04 test.text

ls -l /test2/ total 4 -rw-rw-r-- 1 ubuntu ubuntu 19 Nov 27 23:54 test2.txt

Compose Version

Docker Compose version v2.23.3

Docker Environment

Client:
 Version:    24.0.7
 Context:    default
 Debug Mode: false

Server:
 Containers: 30
  Running: 22
  Paused: 0
  Stopped: 8
 Images: 42
 Server Version: 24.0.7
 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: systemd
 Cgroup Version: 2
 Plugins:
  Volume: local
  Network: bridge host ipvlan macvlan null overlay
  Log: awslogs fluentd gcplogs gelf journald json-file local logentries splunk syslog
 Swarm: inactive
 Runtimes: io.containerd.runc.v2 runc
 Default Runtime: runc
 Init Binary: docker-init
 containerd version: 
 runc version: 
 init version: 
 Security Options:
  apparmor
  seccomp
   Profile: builtin
  cgroupns
 Kernel Version: 6.8.0-48-generic
 Operating System: Ubuntu 24.04.1 LTS
 OSType: linux
 Architecture: x86_64
 CPUs: 16
 Total Memory: 31.3GiB
 Name: server01
 ID: bf8273f3-30ce-4115-89c0-dae74d46a77a
 Docker Root Dir: /mnt/docker-config/docker
 Debug Mode: false
 Experimental: false
 Insecure Registries:
  127.0.0.0/8
 Live Restore Enabled: false

Anything else?

issue is occurring on windows 10 docker desktop 4.35.1

Original file file.text does not exist in your example repo (but [test.txt](https://github.com/Grasume/docker_example/blob/production/docker-compose-bindmount/test/test.txt))
As a result, with a bind mount where source path does not exist, Docker engine standard behavior is to create source as a folder

Assuming this isn't a typo, you can control this behavior using create_host_path attribute, see https://docs.docker.com/reference/compose-file/services/#long-syntax-5