Ask Your Question
1

How can GPU memory be shared among various Docker containers?

asked 2021-08-17 11:00:00 +0000

lalupa gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
3

answered 2023-01-21 21:00:00 +0000

woof gravatar image

GPU memory can be shared among various Docker containers by using NVIDIA Container Toolkit.

  1. First, you need to install NVIDIA Container Toolkit on your host machine. You can follow the instructions mentioned in the official documentation to install it.

  2. Once installed, you need to create a docker-compose file for your containers. In the docker-compose file, you need to specify the runtime as nvidia and the devices as /dev/nvidia0:/dev/nvidia0. This will enable the container to use the GPU.

  3. In the Dockerfile of each container, you can set the environment variable NVIDIAVISIBLEDEVICES to the list of GPUs that the container needs access to.

  4. You can then run the containers using the docker-compose command, and each container will have access to the specified GPUs.

Example docker-compose file:

version: '3'
services:
  gpu-container-1:
    build: ./gpu-container-1
    runtime: nvidia
    devices:
      - /dev/nvidia0:/dev/nvidia0
    environment:
      - NVIDIA_VISIBLE_DEVICES=0,1

  gpu-container-2:
    build: ./gpu-container-2
    runtime: nvidia
    devices:
      - /dev/nvidia0:/dev/nvidia0
    environment:
      - NVIDIA_VISIBLE_DEVICES=2
edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2021-08-17 11:00:00 +0000

Seen: 20 times

Last updated: Jan 21 '23