1

Trying to run masquitto Docker container on Windows. I have directory structure:

..
mosquitto
  config
     -- mosquitto.conf
  data
  log

I run command:

docker run -it -p 1883:1883 -p 9001:9001 -v mosquitto.conf:/mosquitto/config/mosquitto.conf -v /mosquitto/data -v /mosquitto/log eclipse-mosquitto

Got error:

docker: Error response from daemon: source /var/lib/docker/overlay2/c54f317f73085489398e1b2c4ffbc85fbdb18073e8a0fa60f11a7f7222fbc49d/merged/mosquitto/config/mosquitto.conf is not directory.
See 'docker run --help'.

What I do wrong?

UPD

I tried to provide full path to config file on host machine:

docker run -it -p 1883:1883 -p 9001:9001 -v C:/docker_tst/eclipse-mosquitto/mosquitto.conf:/mosquitto/config/mosquitto.conf  eclipse-mosquitto

Got error:

docker: Error response from daemon: OCI runtime create failed: container_linux.go:370: starting container process caused: process_linux.go:459: container init caused: rootfs_linux.go:59: mounting "/run/desktop/mnt/host/c/docker_tst/eclipse-mosquitto/mosquitto.conf" to rootfs at "/var/lib/docker/overlay2/d9a7cbcb0f85b195dc5ee2d0999b3df8c84324552f6c45cf218876e9b96ed826/merged/mosquitto/config/mosquitto.conf" caused: 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.
PS C:\docker_tst\eclipse-mosquitto>
vico
  • 17,051
  • 45
  • 159
  • 315
  • From [this answer](https://stackoverflow.com/a/34135752/4676641), if you're mounting a single file, you should try providing the absolute path. If you're using a bash/zsh shell, can you try: `-v $PWD/mosquitto.conf:/mosquitto/config/mosquitto.conf` – cam Mar 04 '21 at 20:10
  • I do it in Windows. How to provide full path from cmd or PowerShell? – vico Mar 05 '21 at 09:31
  • 1
    I don't know of a convenient way to do that besides converting the path somewhat manually per [this answer](https://stackoverflow.com/a/35316813/4676641) because of how Docker reads paths after the `-v` flag. I ran `Get-Location` in powershell and converted the path: `C:\Users\Username\Path` to `//c/users/username/path/file.conf` for the "host" part of the mount. – cam Mar 05 '21 at 09:48
  • I tried to provide full path to mosquitto.conf on host machine, but got error. More details in question body UPD – vico Mar 05 '21 at 10:09
  • I'm sorry for the back and forth but are you sure that's the right path to the .conf? From your folder structure, it looked like the path to `mosquito.conf` might be in `./mosquito/config/mosquito.conf`? So something like `-v C:/docker_tst/eclipse-mosquitto/mosquito/config/mosquito.conf:/mosquitto/config/mosquitto.conf` instead? – cam Mar 05 '21 at 10:48
  • You are right, thanks ! Not I have no errors :) – vico Mar 05 '21 at 12:23

1 Answers1

4

From the comments, the solution was to provide an absolute path to the single mounted file, per this answer.

On Unix based systems or in Windows Subsystem for Linux, you can do this by running something like:

docker run -v $PWD/filename:/path/in/container IMAGE_NAME

However, the process is different on Windows, per this answer.

In PowerShell, you can run Get-Location or pwd to get the current directory where your file is and switch the \ to / (forward slashes). For this example, the solution was to use this command:

docker run -it -p 1883:1883 -p 9001:9001 -v C:/docker_tst/eclipse-mosquitto/mosquito/config/mosquito.conf:/mosquitto/config/mosquitto.conf  eclipse-mosquitto
cam
  • 4,409
  • 2
  • 24
  • 34