Docker 构成 `docker 运行 --gpu=all` 选项的等价物
Docker compose equivalent of `docker run --gpu=all` option
为了自动执行用于启动 docker 容器的配置(docker run
参数),我正在编写一个 docker-compose.yml
文件。
我的容器应该可以访问 GPU,所以我目前使用 docker run --gpus=all
参数。 Expose GPUs for use 文档中对此进行了描述:
Include the --gpus
flag when you start a container to access GPU
resources. Specify how many GPUs to use. For example:
$ docker run -it --rm --gpus all ubuntu nvidia-smi
不幸的是,Enabling GPU access with Compose doesn't describe this use case exactly. This guide uses the deploy
yaml element, but in the context of reserving machines with GPUs. In fact, another documentation说它会被docker-compose
忽略:
This only takes effect when deploying to a swarm with docker stack deploy, and is ignored by docker-compose up and docker-compose run.
在尝试并解决了一路上的无数问题之后,我意识到这只是文档过时了。
将以下 yaml 块添加到我的 docker-compose.yml
导致 nvidia-smi
可供使用。
deploy:
resources:
reservations:
devices:
- driver: nvidia
count: 1
capabilities: [gpu]
为了自动执行用于启动 docker 容器的配置(docker run
参数),我正在编写一个 docker-compose.yml
文件。
我的容器应该可以访问 GPU,所以我目前使用 docker run --gpus=all
参数。 Expose GPUs for use 文档中对此进行了描述:
Include the
--gpus
flag when you start a container to access GPU resources. Specify how many GPUs to use. For example:$ docker run -it --rm --gpus all ubuntu nvidia-smi
不幸的是,Enabling GPU access with Compose doesn't describe this use case exactly. This guide uses the deploy
yaml element, but in the context of reserving machines with GPUs. In fact, another documentation说它会被docker-compose
忽略:
This only takes effect when deploying to a swarm with docker stack deploy, and is ignored by docker-compose up and docker-compose run.
在尝试并解决了一路上的无数问题之后,我意识到这只是文档过时了。
将以下 yaml 块添加到我的 docker-compose.yml
导致 nvidia-smi
可供使用。
deploy:
resources:
reservations:
devices:
- driver: nvidia
count: 1
capabilities: [gpu]