# How to read a file outside of a docker in Julia

**URL:** https://discourse.julialang.org/t/how-to-read-a-file-outside-of-a-docker-in-julia/20322
**Category:** Offtopic
**Created:** [January 31, 2019, 4:17pm UTC](https://discourse.julialang.org/t/how-to-read-a-file-outside-of-a-docker-in-julia/20322 "2019-01-31T16:17:26Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![ExpandingMan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/expandingman/32/866_2.png) [@ExpandingMan](https://discourse.julialang.org/u/ExpandingMan)
#### Post date: [January 31, 2019, 4:17pm UTC](https://discourse.julialang.org/t/how-to-read-a-file-outside-of-a-docker-in-julia/20322/1 "2019-01-31T16:17:27Z")

</div>

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?

---

<div class="post-metadata">

### Author: ![johnh](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/johnh/32/3615_2.png) [@johnh](https://discourse.julialang.org/u/johnh)
#### Post date: [January 31, 2019, 4:20pm UTC](https://discourse.julialang.org/t/how-to-read-a-file-outside-of-a-docker-in-julia/20322/2 "2019-01-31T16:20:27Z")

</div>

I prefer to use singularity 🙂

Anyway, you would bind mount the filesystem where the file lives.  
[https://4sysops.com/archives/introduction-to-docker-bind-mounts-and-volumes/](https://4sysops.com/archives/introduction-to-docker-bind-mounts-and-volumes/)

---

<div class="post-metadata">

### Author: ![ImreSamu](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/imresamu/32/20677_2.png) [@ImreSamu](https://discourse.julialang.org/u/ImreSamu)
#### Post date: [January 31, 2019, 4:33pm UTC](https://discourse.julialang.org/t/how-to-read-a-file-outside-of-a-docker-in-julia/20322/3 "2019-01-31T16:33:50Z")

</div>

> 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"`

---

<div class="post-metadata">

### Author: ![quinnj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/quinnj/32/11_2.png) [@quinnj](https://discourse.julialang.org/u/quinnj)
#### Post date: [January 31, 2019, 4:36pm UTC](https://discourse.julialang.org/t/how-to-read-a-file-outside-of-a-docker-in-julia/20322/4 "2019-01-31T16:36:19Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![ExpandingMan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/expandingman/32/866_2.png) [@ExpandingMan](https://discourse.julialang.org/u/ExpandingMan)
#### Post date: [January 31, 2019, 4:41pm UTC](https://discourse.julialang.org/t/how-to-read-a-file-outside-of-a-docker-in-julia/20322/5 "2019-01-31T16:41:47Z")

</div>

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](https://docs.docker.com/storage/bind-mounts/#mounting-into-a-non-empty-directory-on-the-container).

---

<div class="post-metadata">

### Author: ![johnh](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/johnh/32/3615_2.png) [@johnh](https://discourse.julialang.org/u/johnh)
#### Post date: [January 31, 2019, 4:50pm UTC](https://discourse.julialang.org/t/how-to-read-a-file-outside-of-a-docker-in-julia/20322/6 "2019-01-31T16:50:33Z")

</div>

ps. Use the force Luke… use the Force…  
Switch to Singularity… you know you want to Luke…  
[https://www.sylabs.io/guides/3.0/user-guide/bind\_paths\_and\_mounts.html](https://www.sylabs.io/guides/3.0/user-guide/bind_paths_and_mounts.html)

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!

---

<div class="post-metadata">

### Author: ![ExpandingMan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/expandingman/32/866_2.png) [@ExpandingMan](https://discourse.julialang.org/u/ExpandingMan)
#### Post date: [January 31, 2019, 4:55pm UTC](https://discourse.julialang.org/t/how-to-read-a-file-outside-of-a-docker-in-julia/20322/7 "2019-01-31T16:55:15Z")

</div>

> [@johnh](#):
>
> 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!

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

---

<div class="post-metadata">

### Author: ![johnh](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/johnh/32/3615_2.png) [@johnh](https://discourse.julialang.org/u/johnh)
#### Post date: [January 31, 2019, 5:27pm UTC](https://discourse.julialang.org/t/how-to-read-a-file-outside-of-a-docker-in-julia/20322/8 "2019-01-31T17:27:21Z")

</div>

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.

> **[Singularity Compatibility with Docker Containers | Sylabs](https://sylabs.io/2018/04/singularity-compatibility-with-docker-containers/)**
>
> Est. reading time: 7 minutes
