docker容器进行文件挂载失败的解决方法

不支持直接挂载文件,会生成与文件同名的目录,导致挂载失败,报错信息如下:

docker: Error response from daemon: failed to create shim task: OCI runtime create failed: runc create failed: unable to start container process: error during container init: error mounting "/var/prometheus" to rootfs at "/etc/prometheus/prometheus.yml": mount /var/prometheus:/etc/prometheus/prometheus.yml (via /proc/self/fd/6), 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

解决方法:先在挂载目录下新建文件,然后再创建并运行容器,例如:

              进入挂载目录:cd   /var/prometheus

              新建待挂载文件:touch  prometheus.yml

              创建并运行容器:

docker run --name=prometheus -d -p 9090:9090 --restart=always  -v /var/prometheus/prometheus.yml:/etc/prometheus/prometheus.yml   prom/prometheus

         

posted @   羊孩  阅读(6019)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下
· 别再用vector<bool>了!Google高级工程师:这可能是STL最大的设计失误
· 单元测试从入门到精通
返回顶端
点击右上角即可分享
微信分享提示