【发布时间】:2021-06-03 11:02:10
【问题描述】:
尝试在 Windows 上运行 masquitto Docker 容器。我有目录结构:
..
mosquitto
config
-- mosquitto.conf
data
log
我运行命令:
docker run -it -p 1883:1883 -p 9001:9001 -v mosquitto.conf:/mosquitto/config/mosquitto.conf -v /mosquitto/data -v /mosquitto/log eclipse-mosquitto
出现错误:
docker: Error response from daemon: source /var/lib/docker/overlay2/c54f317f73085489398e1b2c4ffbc85fbdb18073e8a0fa60f11a7f7222fbc49d/merged/mosquitto/config/mosquitto.conf is not directory.
See 'docker run --help'.
我做错了什么?
更新
我尝试提供主机上配置文件的完整路径:
docker run -it -p 1883:1883 -p 9001:9001 -v C:/docker_tst/eclipse-mosquitto/mosquitto.conf:/mosquitto/config/mosquitto.conf eclipse-mosquitto
出现错误:
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>
【问题讨论】:
-
来自this answer,如果您要挂载单个文件,则应尝试提供绝对路径。如果你使用的是 bash/zsh shell,你可以试试:
-v $PWD/mosquitto.conf:/mosquitto/config/mosquitto.conf -
我在 Windows 中进行。如何提供 cmd 或 PowerShell 的完整路径?
-
除了根据this answer 手动转换路径之外,我不知道有一种方便的方法可以做到这一点,因为 Docker 如何在
-v标志之后读取路径。我在 powershell 中运行Get-Location并将路径:C:\Users\Username\Path转换为//c/users/username/path/file.conf用于挂载的“主机”部分。 -
我尝试在主机上提供 mosquitto.conf 的完整路径,但出现错误。问题正文 UPD 中的更多详细信息
-
我为来回感到抱歉,但您确定这是通向 .conf 的正确路径吗?从您的文件夹结构来看,
mosquito.conf的路径看起来可能在./mosquito/config/mosquito.conf中?那么像-v C:/docker_tst/eclipse-mosquitto/mosquito/config/mosquito.conf:/mosquitto/config/mosquitto.conf这样的东西呢?