经过无数小时的研究,我决定使用以下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的建议和帮助!



