sudo apt-get update
sudo apt-get install \\ca-certificates \\curl \\gnupg \\lsb-release
sudo mkdir -p /etc/apt/keyringscurl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpgecho \\"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \\$(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
sudo apt-get update
sudo apt-get install docker-ce docker-ce-cli containerd.io docker-compose-plugin
distribution=$(. /etc/os-release;echo $ID$VERSION_ID) \\&& curl -fsSL https://nvidia.github.io/libnvidia-container/gpgkey | sudo gpg --dearmor -o /usr/share/keyrings/nvidia-container-toolkit-keyring.gpg \\&& curl -s -L https://nvidia.github.io/libnvidia-container/$distribution/libnvidia-container.list | \\sed 's#deb https://#deb [signed-by=/usr/share/keyrings/nvidia-container-toolkit-keyring.gpg] https://#g' | \\sudo tee /etc/apt/sources.list.d/nvidia-container-toolkit.list
sudo apt-get update
sudo apt-get install -y nvidia-docker2
sudo systemctl restart docker
sudo docker run --rm --gpus all nvidia/cuda:11.0.3-base-ubuntu20.04 nvidia-smi
+-----------------------------------------------------------------------------+| NVIDIA-SMI 450.51.06 Driver Version: 450.51.06 CUDA Version: 11.0 ||-------------------------------+----------------------+----------------------+| GPU Name Persistence-M| Bus-Id Disp.A | Volatile Uncorr. ECC || Fan Temp Perf Pwr:Usage/Cap| Memory-Usage | GPU-Util Compute M. || | | MIG M. ||===============================+======================+======================|| 0 Tesla T4 On | 00000000:00:1E.0 Off | 0 || N/A 34C P8 9W / 70W | 0MiB / 15109MiB | 0% Default || | | N/A |+-------------------------------+----------------------+----------------------++-----------------------------------------------------------------------------+| Processes: || GPU GI CI PID Type Process name GPU Memory || ID ID Usage ||=============================================================================|| No running processes found |+-----------------------------------------------------------------------------+
标记 | 说明 |
latest | TensorFlow CPU 二进制镜像的最新版本。(默认版本) |
nightly | TensorFlow 镜像的每夜版。(不稳定) |
version | 指定 TensorFlow 二进制镜像的版本,例如 2.1.0。 |
devel | TensorFlow master 开发环境的每夜版。包含 TensorFlow 源代码。 |
custom-op |
标记变体 | 说明 |
tag -gpu | 支持 GPU 的指定标记版本。 |
tag -jupyter | 针对 Jupyter 的指定标记版本(包含 TensorFlow 教程笔记本)。 |
docker pull tensorflow/tensorflow # latest stable releasedocker pull tensorflow/tensorflow:devel-gpu # nightly dev release w/ GPU supportdocker pull tensorflow/tensorflow:latest-gpu-jupyter # latest release w/ GPU support and Jupyter
docker run [-it] [--rm] [-p hostPort:containerPort] tensorflow/tensorflow[:tag] [command]
latest
标记的镜像验证 TensorFlow 安装效果。Docker 会在首次运行时下载新的 TensorFlow 镜像:docker run -it --rm tensorflow/tensorflow \\python -c "import tensorflow as tf; print(tf.reduce_sum(tf.random.normal([1000, 1000])))"
bash
shell 会话:docker run -it tensorflow/tensorflow bash
-v hostDir:containerDir -w workDir
参数,装载主机目录并更改容器的工作目录。示例如下:docker run -it --rm -v $PWD:/tmp -w /tmp tensorflow/tensorflow python ./script.py
docker run -it -p 8888:8888 tensorflow/tensorflow:nightly-jupyter
docker run --gpus all -it --rm tensorflow/tensorflow:latest-gpu \\python -c "import tensorflow as tf; print(tf.reduce_sum(tf.random.normal([1000, 1000])))"
docker exec
重复使用容器。bash
shell 会话:docker run --gpus all -it tensorflow/tensorflow:latest-gpu bash
本页内容是否解决了您的问题?