docker目录挂载失败:Check if the specified host path exists and is the expected type

docker目录挂载失败:Check if the specified host path exists and is the expected type

docker目录挂载命令,其目的是为了达到修改linux上的文件同步到容器上,从而实现修改容器的配置文件。

在docker目录挂载或启动容器时报错,具体报错如下:

执行:

shell 复制代码
docker run -it --name mosquitto -p 1883:1883 -p 9001:9001 -v /mosquitto/config/mosquitto.conf:/mosquitto/config/mosquitto.conf -v /mosquitto/data:/mosquitto/data -v /mosquitto/log:/mosquitto/log -d eclipse-mosquitto 
shell 复制代码
docker: Error response from daemon: failed to create task for container: failed to create shim task: OCI runtime create failed: runc create failed: unable to start container process: error during container init: error mounting "/mosquitto/config/mosquitto.conf" to rootfs at "/mosquitto/config/mosquitto.conf": mount /mosquitto/config/mosquitto.conf:/mosquitto/config/mosquitto.conf (via /proc/self/fd/7), flags: 0x5000: 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.

他的意思是说我的/mosquitto/config/mosquitto.conf是目录,不能挂载

  • 首先,你需要确认一下/mosquitto/config/mosquitto.conf这个路径是否存在,并且该路径下是否有mosquitto.conf
    这个文件。如果该文件不存在,则需要先创建该文件。
  • 其次,你需要检查容器启动命令中关于挂载的部分是否正确。在这个错误提示中,可能是因为在挂载时将一个文件挂载到了一个目录上,或者是将一个目录挂载到了一个文件上,导致挂载失败。因此,你需要确认一下挂载的目标路径是否正确,以及该路径是否存在。

报错原因:

我是因为没有写全目录路径,不小心将mosquitto文件夹建在root路径下,应先使用pwd看清楚文件路径

修改后命令:

shell 复制代码
docker run -it --name mosquitto -p 1883:1883 -p 9001:9001 -v /root/mosquitto/config/mosquitto.conf:/mosquitto/config/mosquitto.conf -v /root/mosquitto/data:/mosquitto/data -v /root/mosquitto/log:/mosquitto/log -d eclipse-mosquitto 

目录挂载成功

d eclipse-mosquitto

复制代码
目录挂载成功

![image-20240330101903529](https://img-blog.csdnimg.cn/img_convert/ec8d4a4da9cf443163f00db209f945ab.png)
相关推荐
.冰块.几秒前
VMware+Ubuntu24.04 kubeadm 部署 K8s 1.30.2 三节点集群
运维·云原生·容器·kubernetes·k8s·容器编排
Vitaliy Kostrov(柯维远)1 分钟前
客户端如何检查直播流:从流内标记到停止播放
android·运维·服务器·驱动开发·网络安全·系统架构·cdn
软件工程师文艺1 分钟前
PLM系统的下一个十年:从MBD模型定义到产线仿真的技术路线拆解
运维·服务器·网络
张张123y6 分钟前
后端第十三课:大模型评测(Evals)从 0 到 1——看完面试能讲明白
后端·面试·职场和发展·大模型评测·evals
有为少年10 分钟前
容器内存显示 100%、进程莫名被 Killed 解决方案
机器学习·容器·模型训练·模型推理
禁默23 分钟前
玩客云部署EasyVoice实战:HiNas、Docker、ARMv7、9001与固定地址访问(1)
docker·容器·语音识别·cpolar
她的男孩28 分钟前
JAR 全对仍 checksum mismatch:Forge Admin 把 Flyway 从 filesystem 改成 classpath
java·数据库·spring boot
Brilliantwxx34 分钟前
【Linux】IO(上)全篇:文件本质、C 接口、系统调用与文件描述符
linux·运维·服务器·c语言
北风toto35 分钟前
Linux 服务器通过 tgz 离线部署 Docker
linux·服务器·docker
古法老登瞎折腾36 分钟前
大数据智能运维实战(三):实现第一个运维 MCP 工具——查询节点与组件状态
java·大数据·运维·人工智能·spring ai·mcp