Executing a command in a machine

This is my Dockerfile

# 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();"

# install python
RUN apt-get update && apt-get install -y \
    python3 \
    python3-pip \
    && rm -rf /var/lib/apt/lists/*

CMD ["julia"]

I am using this image in my fly machine.

when i ssh into the machine, I can access those julia packages but if i call the exec on the machine with the command julia demo.jl, I get ERROR: LoadError: ArgumentError: Package CSV not found in current path. - Run import Pkg; Pkg.add("CSV") to install the CSV package. error

I know this is happening because when using exec it is using non interactive shell. What can I do here now?

My guess is that this is due to differences in environment variables, user ID, and the current working directory—rather than an absence of an interactive REPL, per se.

For example…

$ fly m exec 3d* 'bash -c "whoami && printenv HOME && pwd"'
root
/
/

Versus…

$ fly m exec 3d* 'runuser --login root -c "whoami && printenv HOME && pwd"'
root
/root
/root

The runuser command isn’t a panacea, e.g., it clears most environment variables by default, but it’s what I try first when bumping into a “I really want this to be like a login shell instead” situation…


Aside: If you just need to set HOME or JULIA_LOAD_PATH or similar, then env HOME=/root julia demo.jl is a lighterweight alternative.

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.