# Use the official Julia image
FROM julia:1.9
ENV JULIA_CPU_TARGET="generic;sandybridge,-xsaveopt,clone_all;haswell,-rdrnd,base(1)"
# # Install Julia dependencies
RUN julia -e "using Pkg; Pkg.add([\"CSV\", \"DataFrames\", \"Dates\", \"CairoMakie\"])"
RUN julia -e "using Pkg; Pkg.precompile();"
CMD ["julia"]
When i ssh into the container with this image, I can access all the packages. But when I use non interactive shell, I cant access those packages and I get
ERROR: LoadError: ArgumentError: Package CSV not found in current path. - Run import Pkg; Pkg.add("CSV") to install the CSV package.
ERROR: LoadError: Failed to precompile CSV [336ed68f-0bac-5ca0-87d4-7b16caf5d00b] to "/root/.julia/compiled/v1.9/CSV/jl_APriNU". Stacktrace: [1] error(s::String) @ Base ./error.jl:35 [2] compilecache(pkg::Base.PkgId, path::String, internal_stderr::IO, internal_stdout::IO, keep_loaded_modules::Bool) @ Base ./loading.jl:2294 [3] compilecache @ ./loading.jl:2167 [inlined] [4] _require(pkg::Base.PkgId, env::String) @ Base ./loading.jl:1805 [5] _require_prelocked(uuidkey::Base.PkgId, env::String) @ Base ./loading.jl:1660 [6] macro expansion @ ./loading.jl:1648 [inlined] [7] macro expansion @ ./lock.jl:267 [inlined] [8] require(into::Module, mod::Symbol) @ Base ./loading.jl:1611 in expression starting at /electric-summ.jl:4
Since I already precompiled the packages in the dockerfile, I want to avoid precompiling it again.
This is probably unrelated to your latest error, but here are some things I did to address the issue in the quote.
I had to do this in my Dockerfile
# Setting JULIA_CPU_TARGET makes the precompiled code compatible with the runtime target so
# that precompilation doesn't happen again at runtime.
# This actual value for JULIA_CPU_TARGET may need optimization.
# See https://github.com/JuliaLang/julia/issues/50102#issuecomment-1588774131 etc
# including https://github.com/JuliaLang/julia/issues/50102#issuecomment-1592560219
ENV JULIA_CPU_TARGET "generic;sandybridge,-xsaveopt,clone_all;haswell,-rdrnd,base(1)"
I also specified this before precompiling
# Use a special depot path to store precompiled binaries
ENV JULIA_DEPOT_PATH /var/task/.julia
And this later, in case some code didn’t get precompiled
# Allows more precompilation during runtime?
# /var/task is a read-only path during runtime.
ENV JULIA_DEPOT_PATH /tmp/.julia:/var/task/.julia