yml file version must over 2.3, and with docker 19.03+, and newer docker-compose like 1.24.1+
install nvidia-docker2
sudo apt-get -y install nvidia-docker2
then, yml like this:
version: "2.3"
services:
container_name: nvidia
image: nvidia/cuda:10.1-cudnn7-devel-ubuntu16.04
runtime: nvidia
just add runtime