NVIDIA-docker Cheatsheet

TensorFlow Docker requirements

  1. Install Docker on your local host machine.
  2. For GPU support on Linux, install nvidia-docker.

Note: To run the docker command without sudo, create the docker group and add your user. For details, see the post-installation steps for Linux.

Download a TensorFlow Docker image

The official TensorFlow Docker images are located in the tensorflow/tensorflow Docker Hub repository. Image releases are tagged using the following format:

TagDescription
latestThe latest release of TensorFlow CPU binary image. Default.
nightlyNightly builds of the TensorFlow image. (unstable)
versionSpecify the version of the TensorFlow binary image, for example: 1.14.0
develNightly builds of a TensorFlow master development environment. Includes TensorFlow source code.

Each base tag has variants that add or change functionality:

Tag VariantsDescription
tag-gpuThe specified tag release with GPU support. (See below)
tag-py3The specified tag release with Python 3 support.
tag-jupyterThe specified tag release with Jupyter (includes TensorFlow tutorial notebooks)

You can use multiple variants at once. For example, the following downloads TensorFlow release images to your machine:

docker pull tensorflow/tensorflow                     # latest stable release
docker pull tensorflow/tensorflow:devel-gpu           # nightly dev release w/ GPU support
docker pull tensorflow/tensorflow:latest-gpu-jupyter  # latest release w/ GPU support and Jupyter
 

Start a TensorFlow Docker container

To start a TensorFlow-configured container, use the following command form:

docker run [-it] [--rm] [-p hostPort:containerPort] tensorflow/tensorflow[:tag] [command]
 

For details, see the docker run reference.

Examples using CPU-only images

Let's verify the TensorFlow installation using the latest tagged image. Docker downloads a new TensorFlow image the first time it is run:

docker run -it --rm tensorflow/tensorflow \
   python -c "import tensorflow as tf; tf.enable_eager_execution(); print(tf.reduce_sum(tf.random_normal([1000, 1000])))"
 

Success: TensorFlow is now installed. Read the tutorials to get started.

Let's demonstrate some more TensorFlow Docker recipes. Start a bash shell session within a TensorFlow-configured container:

docker run -it tensorflow/tensorflow bash
 

Within the container, you can start a python session and import TensorFlow.

To run a TensorFlow program developed on the host machine within a container, mount the host directory and change the container's working directory (-v hostDir:containerDir -w workDir):

docker run -it --rm -v $PWD:/tmp -w /tmp tensorflow/tensorflow python ./script.py
 

Permission issues can arise when files created within a container are exposed to the host. It's usually best to edit files on the host system.

Start a Jupyter Notebook server using TensorFlow's nightly build with Python 3 support:

docker run -it -p 8888:8888 tensorflow/tensorflow:nightly-py3-jupyter
 

Follow the instructions and open the URL in your host web browser: http://127.0.0.1:8888/?token=...

GPU support

Docker is the easiest way to run TensorFlow on a GPU since the host machine only requires the NVIDIA® driver (the NVIDIA® CUDA® Toolkit is not required).

Install nvidia-docker to launch a Docker container with NVIDIA® GPU support. nvidia-docker is only available for Linux, see their platform support FAQ for details.

Check if a GPU is available:

lspci | grep -i nvidia
 

Verify your nvidia-docker installation:

docker run --runtime=nvidia --rm nvidia/cuda nvidia-smi
 

Note: nvidia-docker v1 uses the nvidia-docker alias, where v2 uses docker --runtime=nvidia.

Examples using GPU-enabled images

Download and run a GPU-enabled TensorFlow image (may take a few minutes):

docker run --runtime=nvidia -it --rm tensorflow/tensorflow:latest-gpu \
   python -c "import tensorflow as tf; tf.enable_eager_execution(); print(tf.reduce_sum(tf.random_normal([1000, 1000])))"
 

It can take a while to set up the GPU-enabled image. If repeatably running GPU-based scripts, you can use docker execto reuse a container.

Use the latest TensorFlow GPU image to start a bash shell session in the container:

docker run --runtime=nvidia -it tensorflow/tensorflow:latest-gpu bash
 

转载于:https://www.cnblogs.com/sddai/p/11116349.html

nvidia-docker是一个可以在docker中使用GPU的工具。它通过在docker上做了一层封装,并调用nvidia-docker-plugin来实现在docker中使用GPU的功能。在安装nvidia-docker之前,需要先安装docker。安装nvidia-docker的步骤如下: 1. 安装docker:使用以下命令安装docker: ``` sudo apt-get install docker ``` 2. 安装NVIDIA驱动:访问NVIDIA驱动官网,下载并安装适合你的显卡的驱动。安装完成后,可以使用以下命令检查是否安装成功: ``` nvidia-smi ``` 3. 安装nvidia-docker:使用以下命令安装nvidia-docker: ``` distribution=$(. /etc/os-release;echo $ID$VERSION_ID) \ && curl -s -L https://nvidia.github.io/nvidia-docker/gpgkey | sudo apt-key add - \ && curl -s -L https://nvidia.github.io/nvidia-docker/$distribution/nvidia-docker.list | sudo tee /etc/apt/sources.list.d/nvidia-docker.list sudo apt-get update sudo apt-get install -y nvidia-docker2 sudo systemctl restart docker ``` 4. 重启docker:使用以下命令重启docker: ``` sudo systemctl restart docker ``` 安装完成后,你就可以使用nvidia-docker来在docker中使用GPU了。 #### 引用[.reference_title] - *1* *3* [安装使用NVIDIA-Docker——可使用GPU的Docker容器](https://blog.csdn.net/m0_67390379/article/details/124477868)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control_2,239^v3^insert_chatgpt"}} ] [.reference_item] - *2* [深度学习docker环境配置之nvidia-docker安装使用](https://blog.csdn.net/qq_41776453/article/details/129794608)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control_2,239^v3^insert_chatgpt"}} ] [.reference_item] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值