Install TensorFlow by docker under Ubuntu16.04

Environment

  • GPU: Nvidia GTX 1080
  • OS: Ubuntu16.04

Docker installation

  • Get Docker for Ubuntu
Install docker complete edition(CE)
  1. Install packages to allow apt to use a repository over HTTPS:
    sudo apt-get install apt-transport-https ca-certificates curl software-properties-common
    
  2. Add Docker’s official GPG key:
    curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
    
  3. Use the following command to set up the stable repository. You always need the stable repository, even if you want to install edge builds as well. (amd64)
    sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
    sudo apt-get update
    sudo apt-get install docker-ce
    
  4. Verify that Docker CE or Docker EE is installed correctly by running the hello-world image.
    sudo docker run hello-world
    

NvidiaDocker installation

# Install nvidia-docker and nvidia-docker-plugin
wget -P /tmp https://github.com/NVIDIA/nvidia-docker/releases/download/v1.0.1/nvidia-docker_1.0.1-1_amd64.deb

sudo dpkg -i /tmp/nvidia-docker*.deb && rm /tmp/nvidia-docker*.deb

# Test nvidia-smi
sudo nvidia-docker run --rm nvidia/cuda nvidia-smi

Install tensorflow

# CPU
docker run -d --name tensor -e PASSWORD='*****' -p 8888:8888 -p 6006:6006 -p 52022:22 gcr.io/tensorflow/tensorflow:latest-gpu-py3 gcr.io/tensorflow/tensorflow

# GPU
nvidia-docker run -d --name tensor -e PASSWORD='********' -p 8888:8888 -p 6006:6006 -p 52022:22 gcr.io/tensorflow/tensorflow:latest-gpu-py3

# GPU and mount 
sudo nvidia-docker run -d --name tensor -e PASSWORD='**' -p xxx.xxx.xxx.xxx:8888:8888 -p xxx.xxx.xxx.xxx:6006:6006 -p xxx.xxx.xxx.xxx:52022:22 -v /media/rvl/Data2/dockermount:/notebooks/rvlssd:z gcr.io/tensorflow/tensorflow:latest-gpu-py3

Login to docker container

sudo docker exec -it tensor bash

Initialize tensorboard:

tensorboard --logdir /root/logs &

Additional command

Start ssh service

apt update
apt install ssh
/etc/init.d/ssh restart
apt-get install vim
sudo vi /etc/ssh/sshd_config 
#PermitRootLogin yes
passwd root

Stop docker

sudo docker stop $(sudo docker ps -a -q)
sudo docker rm $(sudo docker ps -a -q)

Restart exited container in the background

sudo docker start  `sudo docker ps -q -l` # restart it in the background
sudo docker attach `sudo docker ps -q -l` # reattach the terminal & stdin

Comments

  1. The install docker step maybe can simplify with two commands

    ```
    curl -sSL https://get.docker.com | sudo sh
    sudo usermod -aG docker $USER
    ```

    ReplyDelete
    Replies
    1. Thanks for providing these convenient commands.
      I'll update my article after I verify it on my machine. ^_^

      Delete
  2. Thanks a lot very much for the high quality and results-oriented help. I won’t think twice to endorse your blog post to anybody who wants and needs support about this area.
    docker -training-in-chennai

    ReplyDelete
  3. This is good information and really helpful for the people who need information about this.

    It is very useful.Thanks for sharing.Good information. Thanks for sharing with us
    oracle training in chennai

    oracle training institute in chennai

    oracle training in bangalore

    oracle training in hyderabad

    oracle training

    hadoop training in chennai

    hadoop training in bangalore


    ReplyDelete

Post a Comment

Popular posts from this blog

Ubuntu Chrome Remote Desktop Setting

Open3D: A Modern Library for 3D Data Processing