This seems similar to docker/for-win issue 9823, with the exact error message:
If, using the WSL2 backend, I mount a directory at a local path, I can then at a later point mount a file from the same path.
But:
/tmp/docker-repro$ mkdir foo
/tmp/docker-repro$ docker run --rm -v /tmp/docker-repro/foo:/foo ubuntu ls -la foo
# works
Later on:
/tmp/docker-repro$ rm -rf foo/
/tmp/docker-repro$ touch foo # <=== now mount a file, not a folder, should work
/tmp/docker-repro$docker run --rm -v /tmp/docker-repro/foo:/foo ubuntu ls -la foo
docker: Error response from daemon: not a directory.
If that is not your case, you also have docker/compose-cli issue 1795, with a docker-compose.yml:
app:
image: invoiceninja/invoiceninja:5
container_name: InvoiceNinja5
restart: always
volumes:
- ./config/hosts:/etc/hosts:ro
- ./docker/app/public/:/var/www/app/public/:rw,delegated
- ./docker/app/storage/:/var/www/app/storage/:rw,delegated
Resulting in:
Cannot start service app: failed to create shim:
OCI runtime create failed:
container_linux.go:380: starting container process
caused: process_linux.go:545: container init
caused: rootfs_linux.go:76: mounting "/data/compose/8/config/hosts" to rootfs at "/etc/hosts"
caused: mount through procfd: 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
With the root cause being:
You're bind-mounting ./config/hosts from the host into the container; if /data/compose/8/ is your compose project directory, and there's no file named config/hosts, then docker will assume you're trying to bind-mount a directory, and create one.
So you either need to remove that bind-mount from your compose file, or If the intent is to provide a custom /etc/hosts for your container, then you need to create that file before running the compose file.
So it depends on how you are running your Docker container and which directives you used to do your mount.