how should I persistently save Julia packages in a Docker container
You can manage the package and their versions via a Julia Project.toml
file.This file can keep both the list of your dependencies.
Here is a sample Julia session:
julia> using Pkgjulia> pkg"generate MyProject" Generating project MyProject: MyProject\Project.toml MyProject\src/MyProject.jljulia> cd("MyProject")julia> pkg"activate ." Activating environment at `C:\Users\pszufe\myp\MyProject\Project.toml`julia> pkg"add DataFrames"
Now the last step is to provide package version information to your Project.toml
file. We start by checking the version number that "works good":
julia> pkg"st DataFrames"Project MyProject v0.1.0Status `C:\Users\pszufe\myp\MyProject\Project.toml` [a93c6f00] DataFrames v0.21.7
Now you want to edit Project.toml
file [compat]
to fix that version number to always be v0.21.7
:
name = "MyProject"uuid = "5fe874ab-e862-465c-89f9-b6882972cba7"authors = ["pszufe <pszufe@******.com>"]version = "0.1.0"[deps]DataFrames = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0"[compat]DataFrames = "= 0.21.7"
Note that in the last line the equality operator is twice to fix the exact version number see also https://julialang.github.io/Pkg.jl/v1/compatibility/.
Now in order to reuse that structure (e.g. different docker, moving between systems etc.) all you do is
cd("MyProject")using Pkgpkg"activate ."pkg"instantiate"
Additional note
Also have a look at the JULIA_DEPOT_PATH
variable (https://docs.julialang.org/en/v1/manual/environment-variables/).When moving installations between dockers here and there it might be also sometimes convenient to have control where all your packages are actually installed. For an example you might want to copy JULIA_DEPOT_PATH
folder between 2 dockers having the same Julia installations to avoid the time spent in installing packages or you could be building the Docker image having no internet connection etc.
You can persist the state of downloaded & precompiled packages by mounting a dedicated volume into /home/your_user/.julia
inside the container:
$ docker run --mount source=dot-julia,target=/home/your_user/.julia [OTHER_OPTIONS]
Depending on how (and by which user) julia is run inside the container, you might have to adjust the target path above to point to the first entry in Julia's DEPOT_PATH
.
You can control this path by setting it yourself via the JULIA_DEPOT_PATH
environment variable. Alternatively, you can check whether it is in a nonstandard location by running the following command in a Julia REPL in the container:
julia> println(first(DEPOT_PATH))/home/francois/.julia