将编辑后的 ​​conf 文件传递​​给 docker 容器中的 mosquitto 时出错

Error when passing edited conf file to mosquitto in docker container

我在 ubuntu 上尝试 运行 mosquitto docker 时遇到此错误。

docker: 来自守护程序的错误响应:来源 /var/lib/docker/overlay2/a9ce020a555f57/merged/mosquitto/config/mosquitto.conf 不是目录。

我正在运行执行此命令。

sudo docker 运行 -it -p 1883:1883 -p 9001:9001 -v mosquitto.conf:/mosquitto/config/mosquitto.conf eclipse-mosquitto

来自docker docs

When you use a bind mount, a file or directory on the host machine is mounted into a container. The file or directory is referenced by its absolute path on the host machine.

因此您必须将完整(绝对)路径传递给 mosquitto.conf,例如/home/jay/mosquitto/mosquitto.conf(参见 this issue for info on why). You can get your shell to help:

sudo docker run -it -p 1883:1883 -p 9001:9001 -v "$(pwd)"/mosquitto.conf:/mosquitto/config/mosquitto.conf eclipse-mosquitto