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)
相关推荐
韩立学长几秒前
基于Springboot琴行学生课程信息管理系统2gt392wb(程序、源码、数据库、调试部署方案及开发环境)系统界面展示及获取方式置于文档末尾,可供参考。
数据库·spring boot·后端
Y.O.U..3 分钟前
Kubernetes-PV(PersistentVolume)和PVC(PersistentVolumeClaim)
云原生·容器·kubernetes
Curvatureflight4 分钟前
Kubernetes完全指南:从集群搭建到生产部署
云原生·容器·kubernetes
砚边数影6 分钟前
金仓数据库KDMS助力某能源集团完成20TB时序数据智能迁移,效率提升显著、年省运维成本超千万元
运维·数据库·能源·时序数据库·数据库平替用金仓·金仓数据库·kdms
鸠摩智首席音效师7 分钟前
如何在 Linux 中使用 sort 命令排序 ?
linux·运维·服务器
XXOOXRT7 分钟前
基于SpringBoot的用户登录
java·spring boot·后端
齐 飞8 分钟前
springboot整合shardingsphere-jdbc5.1.1-按月分表
数据库·spring boot
Lucky小小吴8 分钟前
Debian 系统 GRUB 引导故障修复全流程教程
运维·debian
Lenyiin10 分钟前
《 Linux 修炼全景指南: 十三 》环境变量
linux·运维·服务器
努力也学不会java16 分钟前
【Spring Cloud】环境和工程基本搭建
java·人工智能·后端·spring·spring cloud·容器