将配置文件传递给 Docker 容器中的 mosquitto
Pass configuration file to mosquitto in Docker container
正在尝试 运行 masquitto Docker 容器 Windows。我有目录结构:
..
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'.
我做错了什么?
UPD
我试图提供主机上配置文件的完整路径:
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>
根据评论,解决方案是根据 .
提供单个安装文件的绝对路径
在基于 Unix 的系统上或 Windows Linux 的子系统中,您可以通过 运行 执行以下操作:
docker run -v $PWD/filename:/path/in/container IMAGE_NAME
但是,根据 。
,Windows 的流程有所不同
在 PowerShell 中,您可以 运行 Get-Location
或 pwd
获取文件所在的当前目录,并将 \
切换为 /
(正斜杠)。对于此示例,解决方案是使用此命令:
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
正在尝试 运行 masquitto Docker 容器 Windows。我有目录结构:
..
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'.
我做错了什么?
UPD
我试图提供主机上配置文件的完整路径:
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>
根据评论,解决方案是根据
在基于 Unix 的系统上或 Windows Linux 的子系统中,您可以通过 运行 执行以下操作:
docker run -v $PWD/filename:/path/in/container IMAGE_NAME
但是,根据
在 PowerShell 中,您可以 运行 Get-Location
或 pwd
获取文件所在的当前目录,并将 \
切换为 /
(正斜杠)。对于此示例,解决方案是使用此命令:
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