栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

在Container中挂载目录并与主机共享

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

在Container中挂载目录并与主机共享

经过无数小时的研究,我决定使用以下Dockerfile扩展映像:

FROM sphinxsearchVOLUME /usr/local/sphinx/etcVOLUME /usr/local/sphinx/varRUN mkdir -p /sphinx && cd /sphinx && cp -avr /usr/local/sphinx/etc . && cp -avr /usr/local/sphinx/var .ADD docker-entrypoint.sh /RUN chmod +x /docker-entrypoint.shENTRYPOINT ["/docker-entrypoint.sh"]

对其进行扩展使我受益匪浅,因为我在测试时不必从头开始构建整个图像,而只需构建相关的部分。

我创建了一个ENTRYPOINT来执行bash脚本,该脚本会将文件复制回所需的目的地以使sphinx正常运行,这是该代码:

#!/bin/shset -etarget=/usr/local/sphinx/etc# check if directory existsif [ -d "$target" ]; then    # check if we have files    if find "$target" -mindepth 1 -print -quit | grep -q .; then        # no files don't do anything        # we may use this if condition for something else later        echo not empty, don't do anything...    else        # we don't have any files, let's copy the        # files from etc and var to the right locations        cp -avr /sphinx/etc/* /usr/local/sphinx/etc && cp -avr /sphinx/var/* /usr/local/sphinx/var    fielse    # directory doesn't exist, we will have to do something here    echo need to creates the directory...fiexec "$@"

可以访问主机上的/ etc&/
var目录,这使我可以调整文件,同时在两次重新启动之间将它们保存在主机上,依此类推…等等,我也将数据保存在主机上,这些数据应该在重新启动后仍然有效。

我知道这是关于数据容器与在主机上存储的争论不休的话题,目前我倾向于在主机上进行存储,但是稍后将尝试其他方法。如果有人有任何提示,建议等…来改善我所拥有的或更好的方法,请分享。

感谢@ h3nrik的建议和帮助!



转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/409251.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号