Search code examples
dockernvidiafile-sharing

Share Existing Host Directory with Docker Container?


Docker allows a directory to be shared among other containers with the -v option.

But it shadows any existing directory on the host.

How can a host directory be made visible to the docker instance?

For example, this creates a mountpoint at /opt:

nvidia-docker run -i -t --name x nvidia/cuda:7.5-runtime-ubuntu14.04 -v /opt

But it shadows the host /opt. This is the safe, usually-desired behavior. But for development and instance setup, it would be immensely useful to have access to an existing file structure.


Solution

  • In order to make your host files visible within your container, you need to specify:

    <host_path>:<container_path>
    

    So in your case:

    docker run -it --name <whatever> -v /opt:/opt