码迷,mamicode.com
首页 > 系统相关 > 详细

Set up Tensorflow-gpu with Docker on Ubuntu 18.04 LTS

时间:2019-01-03 17:25:26      阅读:350      评论:0      收藏:0      [点我收藏+]

标签:user   ext   erp   ips   uninstall   fss   cte   _id   asi   

Set up Tensorflow-gpu with Docker on Ubuntu 18.04 LTS

Docker is the best platform to easily install Tensorflow with a GPU. Here, I want to record What I did to set up tensorflow-gpu with docker on my ubuntu 18.04 LTS.

Step 1: Install Ubuntu 18.04 LTS

The steps are

  1. Check here to download the Ubuntu desktop iso image. For today it’s “ubuntu-18.04.1-desktop-amd64.iso”. Ubuntu 18.10 also works.
  2. Use rufus to prepare a USB stick with the ISO file
  3. Boot your machine with it, and finish the installation. Usually, you won’t have trouble at this stage.
  4. Reboot your machine!

Step 2: Install Proprietary Nvidia Driver

Type the following commands to install proper nvidia driver.

sudo apt update
sudo ubuntu-drivers autoinstall
sudo reboot

When it works well, then reboot machine. If it successfully reboots, open a terminal and use command nvidia-smi. If it properly shows you the status of Nvidia GPU like below, then it‘s already properly installed.

技术分享图片

Step 3: Install Docker CE and Nvidia-Docker2

Uninstall old versions

Old version of Docker were call docker or docker-engine. If are installed, uninstall them:

sudo apt-get remove docker docker-engine docker.io

SET UP THE REPOSITORY

  1. Install packages to allow apt to use a repository over HTTPS
sudo apt-get update
sudo apt-get install     apt-transport-https     ca-certificates     curl     software-properties-common
  1. Add Docker’s official GPG key:
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
  1. Verify that you now have the key with the fingerprint 9DC8 5822 9FC7 DD38 854A E2D8 8D81 803C 0EBF CD88, by searching for the last 8 characters of the fingerprint.
sudo apt-key fingerprint 0EBFCD88
  1. Use the following command to set up the stable repository

    sudo add-apt-repository    "deb [arch=amd64] https://download.docker.com/linux/ubuntu    $(lsb_release -cs)    stable"

INSTALL DOCKER CE

sudo apt-get update
sudo apt-get install docker-ce

INSTALL NVIDIA-DOCKER2

See more information here

# If you have nvidia-docker 1.0 installed: we need to remove it and all existing GPU containers
docker volume ls -q -f driver=nvidia-docker | xargs -r -I{} -n1 docker ps -q -a -f volume={} | xargs -r docker rm -f
sudo apt-get purge -y nvidia-docker

# Add the package repositories
curl -s -L https://nvidia.github.io/nvidia-docker/gpgkey |   sudo apt-key add -
distribution=$(. /etc/os-release;echo $ID$VERSION_ID)
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

# Install nvidia-docker2 and reload the Docker daemon configuration
sudo apt-get install -y nvidia-docker2
sudo pkill -SIGHUP dockerd

# Test nvidia-smi with the latest official CUDA image
docker run --runtime=nvidia --rm nvidia/cuda:9.0-base nvidia-smi

Fetch Image and Run Container

TensorFlow Docker Images

TensorFlow‘s many tags are defined on GitHub, where you can also find extra Dockerfiles. See the full list of tags for the available images.

Tags

  • 1.xx-, latest-, and nightly- tags come with TensorFlow pre-numbered and latest- images contain the latest release, and the nightly images come with the latest TensorFlow nightly Python package.
  • devel images come with Bazel and are ideal for developing changes to TensorFlow (they don‘t have TensorFlow installed, however). /tensorflow_src includes the TensorFlow source tree at a recent known-to-compile commit.
  • custom-op is a special experimental image for developing TF custom ops.
  • -py3 images come with Python 3.5 instead of Python 2.7.
  • -gpu tags are based on Nvidia CUDA. You need nvidia-docker to run them.
  • -jupyter tags include Jupyter and some TensorFlow tutorial notebooks.. They start a Jupyter notebook server on boot. Mount a volume to /tf/notebooks to work on your own notebooks.

Fetch docker‘s images

Choose your favorite version image by tag

docker pull tensorflow/tensorflow:latest-gpu-py3

Run Container

options explain

-v: mount /home/user/notebooks to /root/notebooks on container.

docker run -it --rm --runtime=nvidia     -v /home/user/notebooks:/root/notebooks     tensorflow/tensorflow:latest-gpu-py3 /bin/bash

Tips for Docker

  1. Modify image base on tensorflow/tensorflow

    # enter container
    docker run -it tensorflow/tensorflow /bin/bash
    # install vim on container
    apt install vim

    If it work well, then type ctrl+p and then type ctrl+q to return ubuntu system but container still running.

  2. Save modify

    # list running container and get container id
    docker ps 
    # copy modified container named container-name
    # if container-name equal to current container name, it‘s overwrite;
    # else it‘s copy and save as a new container
    docker commit <container-id> <container-name>

Set up Tensorflow-gpu with Docker on Ubuntu 18.04 LTS

标签:user   ext   erp   ips   uninstall   fss   cte   _id   asi   

原文地址:https://www.cnblogs.com/ychuch/p/10215184.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!