Docker remote - unknown: Are you trying to mount a directory onto a file (or vice-versa)?

Good afternoon.

I have a Docker remote environment exposed via TCP:

  • Rocky Linux 9
  • Docker version 20.10.23 build 7155243
  • 16GB RAM
  • Remote development environment (Inside of the Local Area Network)

Sounds great!

I have 2 laptops, MacBook Pro M1 (2021) Ventura 13.2 with the latest Docker desktop version installed, and ThinkPad x270 with Rocky Linux 9 with the latest Docker version installed too.

Both go to remote local environments.

When I try to run docker compose -f docker-compose-local.yml up -d I got this message on Mac, but I got the same messages for Linux:

[+] Running 2/3
 ⠿ Container webapp-mysql-1   Running                                                                                                                               0.0s
 ⠿ Container webapp-php-1     Starting                                                                                                                              0.4s
 ⠿ Container webapp-apache-1  Recreated                                                                                                                             0.1s
Error response from daemon: failed to create shim task: OCI runtime create failed: runc create failed: unable to start container process: error during container init: error mounting "/Users/sincorchetes/php-fpm.conf" to rootfs at "/opt/bitnami/php/etc/php-fpm.conf": mount /Users/sincorchetes/php-fpm.conf:/opt/bitnami/php/etc/php-fpm.conf (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

However, If I clone the repository and run it on the remote host, It’s working. What’s happened?

You can’t bind mount a local file to a remote machine or virtual machine in general. It works with Docker Desktop’s virtual machine because the the Desktop mounts some folders into the virtual machine and the Docker daemon inside that virtual machine can find it.

If you want to work with remote servers, you can build docker images and copy the configuration files into the image.

docker build will copy the required files to the server that runs the Docker daemon. This is why you could see (without buildkit) that docker build creates an archive file from the build context which takes time and we use .dockerignore files to avoid copying files that we don’t really want to copy.

Buildkit builds images differently, but it will still copy the requires files (not the entire build context) to the server.
If you need bind mounts for data, you need to create it or (depending on the syntax of the compose file) let Docker creating the folder. Since php-fpm.conf obviously didn’t exist on the server, Docker most have created it for you as a folder and now you try to mount a folder onto a file in the container.