How to read a file outside of a docker in Julia

I’m rather unsure if the solution to this will come from Julia, but I’m having a very hard time figuring out how to do this, so I thought I’d ask here.

So, I have a Julia program that I want to run from the command line and which I have put in its own docker container. The program takes a file as input. When I run outside of docker, I give the filename as an argument and it works. When I run the docker container, Julia says it can’t find the file, presumably because the file is not in the container.

Does anyone know how I can get the container to read a file into Julia which is outside the container?

I prefer to use singularity :slight_smile:

Anyway, you would bind mount the filesystem where the file lives.


Does anyone know how I can get the container to read a file into Julia which is outside the container?

on Linux you can use the -v (volume) parameters:

simple example: mapping the current directory to docker /juliawrk:

docker run -it --rm -v $(pwd):/juliawrk julia:1.1 bash -c "cd /juliawrk && ls -la && julia"

1 Like

Yeah, it doesn’t really work to just pass a file as a command line argument to the docker container. You either need to ADD/COPY the input file into the docker container itself (i.e. build it into the docker), or as other’s have suggested, using volume mounts, which is essentially telling your docker container to use a volume mount so it can access files there.

1 Like

Thanks all. This is slightly more elaborate than what I was hoping for, but seeing your posts I now remember having done this in the past.

Just for anyone else who’s stuck on this, also see the relevant part of the docker documentation.

ps. Use the force Luke… use the Force…
Switch to Singularity… you know you want to Luke…

Last time I built a Singularity container it just bind mounted my home directory without any further configuration.
Which meant that my .julia directory was just there!

1 Like

That’s probably not even something I’d want in the general case, but I’ll check it out.

Apologies for doing this one to death…
I just ran up a Singularity container I build in November 2018.
It automatically mounted my home directory AND /var/tmp from the host system.
So you could put your file into /var/tmp

You should be able to use your existing Docker container also.