【问题标题】:Pass configuration file to mosquitto in Docker container将配置文件传递给 Docker 容器中的 mosquitto
【发布时间】: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 这样的东西呢?

标签: docker mosquitto


【解决方案1】:

在 cmets 中,解决方案是根据 this answer 提供单个挂载文件的绝对路径。

在基于 Unix 的系统或适用于 Linux 的 Windows 子系统中,您可以通过运行以下命令来做到这一点:

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

但是,根据this answer,该过程在 Windows 上有所不同。

在 PowerShell 中,您可以运行 Get-Locationpwd 以获取文件所在的当前目录,并将 \ 切换为 /(正斜杠)。对于此示例,解决方案是使用以下命令:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-06-23
    • 2021-10-16
    • 2019-05-25
    • 2017-04-26
    • 1970-01-01
    • 1970-01-01
    • 2018-04-22
    相关资源
    最近更新 更多