I can't mount a file in volume in docker compose

I want to mount a file logstash in volume
I use this configuration in docker-compose file :

      - type: bind
        source: ./logstash.conf/
        target: /usr/share/logstash/pipeline/logstash.conf

but the logstash mounted as a directory not as a file

I work on windows 11
what is the problem ?

If the source path ends with a slash or actually is a folder, then a folder will be mounted. Try without the trailing slash.

1 Like

I delete the slash but the logstash is mounted as a folder not as a file

I just tested it without docker-compose in a powershell terminal on Windows 11/Docker Desktop 4.19:

date > date.txt
docker run --rm -ti -v "${pwd}\date.txt:/date.txt" alpine cat /date.txt
# output:
# Donnerstag, 18. Mai 2023 09:55:59

The container binds the single file and renders the ouput in the terminal.

Then I tried it with following compose file (in the same folder where date.txt already exists)

    image: alpine:latest
      - type: bind
        source: ./date.txt
        target: /date.txt
    command: cat /date.txt

Then run it:

docker compose -p test up
#[+] Running 2/2
# - Network test_default   Created                                                                                  0.0s
# - Container test-bind-1  Created                                                                                  0.1s
#Attaching to test-bind-1
#test-bind-1  |
#test-bind-1  | Donnerstag, 18. Mai 2023 09:55:59
#test-bind-1  |
#test-bind-1 exited with code 0

It works as expected.

1 Like

Check the files on the host and make sure you are using the correct filename and logstash.conf is not already a folder on the host. Bind mounting with the long syntax should not create a host path unless create_host_path was set to true, but I remember that it happened to me before so some years ago with an older compose version.

I use Docker Desktop for Mac and it works as @meyay described.