Search code examples
dockervagrantnvidia-docker

How to run Vagrant with nvidia docker as provider


I'm part of a team developing a machine learning application.

currently we're using Vagrant with a Docker provider as a uniform dev environment.

We want to utilize the GPUs on our computers when we play around during development, and I found that Nvidia released nvidia-docker to enable that for a simple docker container.

How can I use nvidia-docker as a provider for Vagrant?

If it's not possible, is there any equivalent solution?


It is important for us to develop on top of the same docker image that we deploy since we depend on multiple interacting opensource libraries, and we want to manage them in one place

(no dependencies breaking when deploying)


Solution

  • docker 19.0.3 (release notes) added a --gpus argument to their docker run command

    which we can provide through vagrant's create_args docker configuration option, docs:

    create_args (array of strings) - Additional arguments to pass to docker run when the container is started. This can be used to set parameters that are not exposed via the Vagrantfile.

    so after adding this line, the GPUs will be exposed in the VM

    config.vm.provider "docker" do |d|
        ...
        d.create_args = ["--gpus", "all"]
        ...
    end