Docker转Singularity部署Julia应用Whippet遇只读文件系统错误求助
解决Singularity运行Julia Whippet镜像时无法写入manifest_usage.toml的问题
我正在为Julia工具Whippet制作可同时在Docker和Singularity(singularity-ce 3.9.5)中运行的镜像。Docker镜像运行正常,但Singularity中执行时会报错无法写入/depot/logs/manifest_usage.toml,原因是Singularity以普通用户身份运行,而非Docker默认的root。
当前使用的Dockerfile
FROM julia:bullseye LABEL version=v1.6.1 RUN apt-get update && apt-get install -y git RUN mkdir /depot ENV JULIA_PATH=/usr/local/julia ENV JULIA_DEPOT_PATH=/depot ENV JULIA_PROJECT=/whippet RUN mkdir /whippet/ && cd /whippet && \ git clone --depth 1 --branch v1.6.1 https://github.com/timbitz/Whippet.jl.git . && \ julia --project=/whippet -e 'using Pkg; Pkg.instantiate(); Pkg.precompile();' RUN chmod 777 -R /depot/ ENV PATH="/whippet/bin/:${PATH}" RUN whippet-quant.jl -h || echo "Done" RUN whippet-index.jl -h || echo "Done" RUN whippet-delta.jl -h || echo "Done" ENTRYPOINT ["whippet-quant.jl"]
已尝试的无效操作
- 更换
JULIA_DEPOT_PATH到不同位置(包括默认的~/.julia) - 创建新用户
运行对比
- Docker正常运行命令:
docker run cloxd/whippet:1.6.1 -h - Singularity报错信息:
singularity run docker://cloxd/whippet:1.6.1 INFO: Using cached SIF image Whippet v1.6.1 loading... Activating project at `/whippet` ERROR: LoadError: SystemError: opening file "/depot/logs/manifest_usage.toml": Read-only file system Stacktrace: [1] systemerror(p::String, errno::Int32; extrainfo::Nothing) @ Base ./error.jl:176 [2] #systemerror#80 @ ./error.jl:175 [inlined] [3] systemerror @ ./error.jl:175 [inlined] [4] open(fname::String; lock::Bool, read::Nothing, write::Nothing, create::Nothing, truncate::Nothing, append::Bool) @ Base ./iostream.jl:293 [5] open(f::Pkg.Types.var"#44#46"{String}, args::String; kwargs::Base.Pairs{Symbol, Bool, Tuple{Symbol}, NamedTuple{(:append,), Tuple{Bool}}}) @ Base ./io.jl:382 [6] write_env_usage(source_file::String, usage_filepath::String) @ Pkg.Types /usr/local/julia/share/julia/stdlib/v1.8/Pkg/src/Types.jl:487 [7] Pkg.Types.EnvCache(env::Nothing) @ Pkg.Types /usr/local/julia/share/julia/stdlib/v1.8/Pkg/src/Types.jl:345 [8] EnvCache @ /usr/local/julia/share/julia/stdlib/v1.8/Pkg/src/Types.jl:325 [inlined] [9] add_snapshot_to_undo(env::Nothing) @ Pkg.API /usr/local/julia/share/julia/stdlib/v1.8/Pkg/src/API.jl:1862 [10] add_snapshot_to_undo @ /usr/local/julia/share/julia/stdlib/v1.8/Pkg/src/API.jl:1858 [inlined] [11] activate(path::String; shared::Bool, temp::Bool, io::Base.TTY) @ Pkg.API /usr/local/julia/share/julia/stdlib/v1.8/Pkg/src/API.jl:1700 [12] activate(path::String) @ Pkg.API /usr/local/julia/share/julia/stdlib/v1.8/Pkg/src/API.jl:1659 [13] top-level scope @ /whippet/bin/whippet-quant.jl:12 in expression starting at /whippet/bin/whippet-quant.jl:12
解决建议
1. 禁用Julia的manifest使用日志
在Dockerfile中添加环境变量,直接阻止Julia生成manifest_usage.toml文件:
ENV JULIA_PKG_NO_MANIFEST_USAGE=true
也可以在Whippet的启动脚本(如whippet-quant.jl)开头添加Julia代码:
ENV["JULIA_PKG_NO_MANIFEST_USAGE"] = "true"
2. 调整Singularity运行时挂载可写目录
运行Singularity时,将本地可写目录挂载到Julia需要写入的路径:
# 仅挂载日志目录 singularity run -B $HOME/.julia/logs:/depot/logs docker://cloxd/whippet:1.6.1 # 或挂载整个depot目录 singularity run -B $HOME/.julia:/depot docker://cloxd/whippet:1.6.1
3. 将可写目录指向Singularity允许的临时路径
在Dockerfile中修改JULIA_DEPOT_PATH,把可写部分指向/tmp(Singularity默认允许写入该目录):
RUN mkdir -p /tmp/julia_depot/logs RUN chmod 777 -R /tmp/julia_depot/ ENV JULIA_DEPOT_PATH="/depot:/tmp/julia_depot"
4. 预编译时提前禁用写入操作
修改Dockerfile中的预编译命令,提前设置环境变量避免生成日志:
RUN julia --project=/whippet -e 'ENV["JULIA_PKG_NO_MANIFEST_USAGE"] = "true"; using Pkg; Pkg.instantiate(); Pkg.precompile();'
内容的提问来源于stack exchange,提问作者Claudio Lorenzi
相关产品推荐
相关产品推荐

