Configuring Docker Image of Julia. Julia can't see installed packages

Presently I have three files that are referenced in my docker script. I’ll provide the docker script and then the miscellaneous files.


# src:

FROM julia:latest

RUN apt-get update && apt-get upgrade -y && apt-get install  -y \
    apt-utils gcc g++ openssh-server cmake build-essential \
    gdb gdbserver rsync vim locales
RUN apt-get install -y bzip2 wget gnupg dirmngr apt-transport-https \
    ca-certificates tmux && \
    apt-get clean 
# setup ssh
RUN mkdir /var/run/sshd &&  \
    echo 'root:my_password' |chpasswd && \
    sed -ri 's/^#?PermitRootLogin\s+.*/PermitRootLogin yes/' /etc/ssh/sshd_config && \
    sed -ri 's/UsePAM yes/#UsePAM yes/g' /etc/ssh/sshd_config && \
    mkdir /root/.ssh

# remove leftovers
RUN rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*

# Expose 22 for ssh server. 7777 for gdb server
EXPOSE 22 7777

# add user for debugging
RUN useradd -ms /bin/bash debugger
RUN echo 'debugger:my_password' | chpasswd

# start server
CMD ["/usr/sbin/sshd", "-D"]

# add support for English
COPY locale.gen /etc/locale.gen
RUN locale-gen

# add julia packages
COPY install.jl /etc/install.jl
RUN julia /etc/install.jl


using Pkg
pkg"add DataFrames"
pkg"add GLM"
pkg"add LinearAlgebra"
pkg"add Statistics"
pkg"add LaTeXStrings"
pkg"add Random"
pkg"add Distributions"
pkg"add StaticGraphs"
pkg"add GraphPlot"
pkg"add LightGraphs"
pkg"add Colors"
pkg"add Plots"


en_US.UTF-8 UTF-8

Built the container with the following command

sudo docker build -t julia-container .

Finally, I used VSCode to spin up the instance and attach to it. I could run lines that didn’t require any packages but if I tried to run

using Plots

Then I got an error asking me to do using Pkg; Pkg.add("Plots")

(Eventually I’d like to get to where I can host a jupyter notebook hosting Julia on docker and access it from my computer but figuring out the basics is proving to be ambitious haha)

Are you running the image as your debugger user? If so, that explains this; you install everything as root, so they end up in /root/.julia/environments/... but the debugger user looks in /home/debugger/.julia/environments/....

Extending on the answer of @fredrikekre:
You need to set the JULIA_DEPOT_PATH for your user (if it is not root).

As an example, you can take a look at the Dockerfile for Pluto:

Here’s what I ended up doing

FROM ubuntu:latest

RUN apt-get update && \
    apt-get install -y wget && \
    rm -rf /var/lib/apt/list/*


RUN mkdir /opt/julia-${JULIA_VERSION} && \
    cd /tmp && \
    wget -q`echo ${JULIA_VERSION} | cut -d. -f 1,2`/julia-${JULIA_VERSION}-linux-x86_64.tar.gz && \
    tar xzf julia-${JULIA_VERSION}-linux-x86_64.tar.gz -C /opt/julia-${JULIA_VERSION} --strip-components=1 && \
    rm /tmp/julia-${JULIA_VERSION}-linux-x86_64.tar.gz

RUN ln -fs /opt/julia-*/bin/julia /usr/local/bin/julia

# Add packages and precompile 
RUN julia -e 'import Pkg; Pkg.update()' && \
         julia -e 'import Pkg; Pkg.add("Plots"); using Plots' && \
         julia -e 'import Pkg; Pkg.add("Distributions"); using Distributions' && \
         julia -e 'import Pkg; Pkg.add("IJulia"); using IJulia'

# Set up Jupyter    
RUN apt-get install -y build-essential python3.8 python3-pip python3-dev
RUN pip3 -q install pip --upgrade

RUN pip3 install jupyter

WORKDIR /src/notebooks

ADD${TINI_VERSION}/tini /usr/bin/tini
RUN chmod +x /usr/bin/tini
ENTRYPOINT ["/usr/bin/tini", "--"]

CMD ["jupyter", "notebook", "--port=8888", "--no-browser", "--ip=", "--allow-root"]
1 Like