How can I use a local file in a container?

I am trying to create a container to run a program. I am using a pre-configured image and now I need to run the program. However, this is a machine learning program, and I need a dataset from my computer to run.

File is too large to copy to container. It would be better if the program running in the container looked for the data set in the local directory of my computer, but I do not know how to do it.

Is there a way to make this link using the docker command? Or using a dockerfile?

+26
source share
1 answer

Yes you can do it. What you are describing is binding. See https://docs.docker.com/storage/bind-mounts/ for documentation on this.

For example, if I want to mount a folder from my home directory to /mnt/mydata in a container, I can do:

 docker run -v /Users/andy/mydata:/mnt/mydata myimage 

Now /mnt/mydata inside the container will have access to /Users/andy/mydata on my host.

Remember that if you use Docker for Mac or Docker for Windows, there are certain directories on the host that are enabled by default:

If you use the Docker Machine on Mac or Windows, your Docker Engine daemon has only limited access to your macOS or Windows file system. Docker Machine is trying to automatically share your directory with / Users (macOS) or C: \ Users (Windows). This way you can mount files or directories on macOS using.

July 2019 update:

I updated the documentation link and named it to be correct. These types of mounts are called "mounts." The Docker snippet for Mac or Windows no longer appears in the documentation, but should still apply. I'm not sure why they deleted it (my Docker for Mac still has an explicit list of allowed mount paths on the host).

+39
source

Source: https://habr.com/ru/post/1269419/


All Articles