Cant mount a file using docker compose

The following works

    volumes:
      - ./ghost-data:/var/lib/ghost/content

but I am now wanting to mount config.production.json to ./

The file exists in the container:

root@services-dmz:/home/sysadmin/docker/ghost# docker exec -it ghost-ghost-1 bash
fe847b8d491f:/var/lib/ghost# ls
config.development.json  config.production.json   content                  content.orig             current                  versions
fe847b8d491f:/var/lib/ghost#

But when I try

    volumes:
      - ./ghost-data:/var/lib/ghost/content
      -./:/var/lib/ghost/config.production.json

I get

Error response from daemon: failed to create task for container: failed to create shim task: OCI runtime create failed: runc create failed: unable to start container process: error during container init: error mounting ā€œ/home/sysadmin/docker/ghostā€ to rootfs at ā€œ/var/lib/ghost/config.production.jsonā€: mount /home/sysadmin/docker/ghost:/var/lib/ghost/config.production.json (via /proc/self/fd/6), flags: 0x5000: not a directory: unknown: Are you trying to mount a directory onto a file (or vice-versa)? Check if the specified host path exists and is the expected type

I have also tried:

    volumes:
      - ./ghost-data:/var/lib/ghost/content
      -./config.production.json:/var/lib/ghost/config.production.json

Which returns the same error but creates a directory called config.production.json on the mounted volume.

I have read a number of posts but canā€™t work out what I am doing wrong.

You misunderstand what ā€œmountingā€ means. You donā€™t mount a file from the container to outside the container, but the other way around. The file has to exist on the host.

More about volumes here in my blogpost: Everything about Docker volumes - DEV Community

1 Like

Ok, understanding that does help :slight_smile:
Many thanks, all sorted now.