Page tree

Welcome to FreeSoftwareServers Confluence Wiki

Skip to end of metadata
Go to start of metadata

https://docs.docker.com/compose/gpu-support/

https://stackoverflow.com/questions/43368470/use-nvidia-docker-from-docker-compose

https://docs.nvidia.com/datacenter/cloud-native/container-toolkit/user-guide.html

WD=/opt/nvidia
mkdir -p $WD/{setup,conf}
cd $WD/setup
cat << 'EOF' >docker-compose.yaml
version: '3.7'

services:
 nvidia:
    container_name: nvidia
    image: nvidia/cuda:10.2-base
    hostname: nvidia
    runtime: nvidia
    command: ${command}
    environment:
      - 'TZ=${TZ}'
      - 'NVIDIA_VISIBLE_DEVICES=${NVIDIA_VISIBLE_DEVICES}'

    #deploy:
    #  resources:
    #    reservations:
    #      devices:
    #      - capabilities: [gpu]
EOF
chmod +x docker-compose.yaml
cd $WD/setup
cat << 'EOF'>.env
TZ=America/Whitehorse
NVIDIA_VISIBLE_DEVICES=All
command=nvidia-smi
#command=python -c "import tensorflow as tf;tf.test.gpu_device_name()"
EOF
chmod +x .env
WD=/opt/nvidia/setup
cat << EOF >$WD/nvidia.service.setup.sh
cat << EOL >/lib/systemd/system/nvidiadockertest.service
[Unit]
Description=nvidiadockertest_Docker
Requires=docker.service network-online.target

[Service]

Restart=on-abnormal
ExecStart=/usr/bin/docker-compose --project-name nvidiadockertest --project-directory $WD -f $WD/docker-compose.yaml up
ExecStop=/usr/bin/docker-compose --project-name nvidiadockertest --project-directory $WD -f $WD/docker-compose.yaml stop

[Install]
WantedBy=multi-user.target
EOL
systemctl enable nvidiadockertest
systemctl restart nvidiadockertest
systemctl status nvidiadockertest
EOF
chmod +x $WD/nvidiadockertest.service.setup.sh
$WD/nvidiadockertest.service.setup.sh
 
 
  • No labels