How to install packages to non-root in Dockerfile

FROM julia:1.9

WORKDIR /my_folder
RUN useradd -u 1001 sarit -d /my_folder
RUN chown sarit /my_folder
USER sarit

RUN julia -e 'using Pkg; Pkg.add("Pluto", preserve=PRESERVE_DIRECT);'
RUN julia -e 'using Pkg; Pkg.add("IJulia", preserve=PRESERVE_DIRECT);'

It successfully build my image, but it does install for root. For technical reason. I would like to run notebook which is not allow me to run by root. I have to install packages to non-root aka sarit user.

julia> using IJulia
 │ Package IJulia not found, but a package named IJulia is available from a registry.
 │ Install package?
 │   (@v1.9) pkg> add IJulia
 └ (y/n/o) [y]:

How can I achieve that?

Everything works just fine if I copy that Dockerfile, build it, and run it. Perhaps your example is minimized a bit too much to reproduce your problem.

1 Like

Thank you for response. I found an alternative solution by using another ready-made image.

https://hub.docker.com/layers/jupyter/datascience-notebook/julia-1.7.2/images/sha256-919e600af3ab19bc9ff4c07297852faeadecdc94af4e75ef657c9b31d7f3b9a5