Set up Tensorflow-gpu with Docker on Ubuntu 18.04 LTS
Posted ychuch
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Set up Tensorflow-gpu with Docker on Ubuntu 18.04 LTS相关的知识,希望对你有一定的参考价值。
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
- 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.
- Use rufus to prepare a USB stick with the ISO file
- Boot your machine with it, and finish the installation. Usually, you won’t have trouble at this stage.
- 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
- 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
- Add Docker’s official GPG key:
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
- 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
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
# 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-
, andnightly-
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
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 typectrl+q
to return ubuntu system but container still running.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的主要内容,如果未能解决你的问题,请参考以下文章
How to set up a clipping rectangle ?
set about和set out和set aside和set back和set off和set up区别,