Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Complete steps to install tensorflow based on docker

2025-01-30 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/02 Report--

Preface

Google has once again become a great god worshiped by everyone. Google is guiding the direction of machine learning. At the same time, docker is also a very good tool, greatly facilitates the construction of the development environment, before the need to configure and install. Recently in self-learning machine learning, the hot Tensorflow naturally can not be missed, so first solve the installation problem, in order not to affect the local environment, so this article is based on Docker to install Tensorflow, my environment is Ubuntu16.04.

Install Docker

Docker is divided into CE and EE, here we choose CE, that is, the regular community version, first remove the old version that may exist on this machine.

Remove the old version

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

Install optional kernel module

After Ubuntu14.04, some tailored systems will move some kernel modules to the optional kernel package, often starting with linux-image-extra-*, and the storage layer driver AUFS recommended by Docker is included in the optional kernel module package, so it is recommended to install the optional kernel module package. You can install it using the following command:

$sudo apt-get update$ sudo apt-get install\ linux-image-extra-$ (uname-r)\ linux-image-extra-virtual

Certificate and key preparation

Before formal installation, we need to add certificates and packages transferred by HTTPS to ensure that the software is not tampered with during download:

$sudo apt-get update$ sudo apt-get install\ apt-transport-https\ ca-certificates\ curl\ software-properties-common

Add the GPG key of the software source:

$curl-fsSL https://mirrors.ustc.edu.cn/docker-ce/linux/ubuntu/gpg | sudo apt-key add-# official source # $curl-fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add-

Finally, add the Docker software source:

$sudo add-apt-repository\ "deb [arch=amd64] https://mirrors.ustc.edu.cn/docker-ce/linux/ubuntu\ $(lsb_release-cs)\ stable" # official Source # $sudo add-apt-repository\ # "deb [arch=amd64] https://download.docker.com/linux/ubuntu\ # $(lsb_release-cs)\ # stable"

Install Docker

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

Establish a docker user group

Docker usually uses Unix socket to communicate with the Docker engine, and usually only users of root and docker groups can access the socket, otherwise you will sudo all the time, so it is best to add users who currently need to use docker to the docker group.

Establish a docker user group

$sudo groupadd docker

Add the current user to the user group

$sudo usermod-aG docker $USER

Finally, log in to the system again.

Test Docker

Ensure that the service starts

$sudo service docker start

Testing with HelloWorld

Test whether the installation is successful

Docker run hello-worldUnable to find image 'hello-world:latest' locallylatest: Pulling from library/hello-worldca4f61b1923c: Pull complete Digest: sha256:083de497cff944f969d8499ab94f07134c50bcf5e6b9559b27182d3fa80ce3f7Status: Downloaded newer image for hello-world:latestHello from docking this message shows that your installation appears to be working correctly.To generate this message, Docker took the following steps: 1. The Docker client contacted the Docker daemon. 2. The Docker daemon pulled the "hello-world" image from the Docker Hub. (amd64) 3. The Docker daemon created a new container from that image which runs the executable that produces the output you are currently reading. 4. The Docker daemon streamed that output to the Docker client, which sent it to your terminal.To try something more ambitious, you can run an Ubuntu container with: $docker run-it ubuntu bashShare images, automate workflows, and more with a free Docker ID: https://cloud.docker.com/For more examples and ideas, visit: https://docs.docker.com/engine/userguide/

If it can be displayed, it proves that the installation is successful.

Install Tensorflow

With Docker, there is little difficulty in installing Tensorflow.

Download the image

Docker pull tensorflow/tensorflow

When the download is completed, it is displayed:

Status: Downloaded newer image for tensorflow/tensorflow:latest

Create a Tensorflow container

Docker run-- name my-tensorflow-it-p 8888my-tensorflow-it 8888-v / tensorflow:/test/data tensorflow/tensorflow--name: container name created, i.e. my-tensorflow-it: reserved command line run p 8888 tensorflow:/test/data tensorflow/tensorflow--name: map local port 8888 and http://localhost:8888/-v ~ / tensorflow:/test/data: mount local ~ / tensorflow to / test/data in the container tensorflow/tensorflow: default is tensorflow/tensorflow:latest, specify the image to be used

After entering the above command, the default container is started, and the command line displays:

[I 15:08:31.949 NotebookApp] Writing notebook server cookie secret to / root/.local/share/jupyter/runtime/notebook_cookie_ secret[W 15:08:31.970 NotebookApp] WARNING: The notebook server is listening on all IP addresses and not using encryption. This is not recommended. [I 15http://[all 08Serving notebooks from local directory 31.975 NotebookApp] Serving notebooks from local directory: / notebooks [I 15Vera 08VR 31.975 NotebookApp] 0 active kernels [I 15V 08V 31.975 NotebookApp] The Jupyter Notebook is running at: [I 15Vera 08notebooks 31.975 NotebookApp] ip addresses on your system]: 8888/?token=649d7cab1734e01db75b6c2b476ea87aa0b24dde56662a27 [I 1508Serving notebooks from local directory 31.975 NotebookApp] Use Control-C to stop this server and shut down all kernels (twice to skip confirmation). [C 15: 08:31.975 NotebookApp] Copy/paste this URL into your browser when you connect for the first time To login with a token: [I 15 GET 09 NotebookApp] 302 GET /? token=649d7cab1734e01db75b6c2b476ea87aa0b24dde56662a27 (172.17.0.1) 0.42ms

Copy URL with token and open it in a browser

Http://[all ip addresses on your system]: 8888/?token=649d7cab1734e01db75b6c2b476ea87aa0b24dde56662a27

The display is as follows:

Shows that the Jupyter Notebook,Jupyter Notebook (formerly known as IPython notebook) is an interactive notebook. An introductory tutorial for Tensorflow has been shown in the example. Click on one to see

As in the above example, we use tensorflow to add the two array together. We can click run to see the running result.

Close the container

Docker stop my-tensortflow

Open it again

Docker start my-tensortflow

If you don't like using Jupyter Notebook, we can also create a command-line-based container

Command line-based container

Docker run-it-- name bash_tensorflow tensorflow/tensorflow / bin/bash

So we created a container called bash_tensorflow

Or start the container with the start command:

Docker start bash_tensorflow

Then connect the container:

Docker attach bash_tensorflow

You can see that we connected the container with a terminal, just like we did with Linux.

This image does not have vim installed by default, so I downloaded vim to write the code.

At this point, the installation process is complete.

Summary

The above is the whole content of this article, I hope that the content of this article has a certain reference and learning value for your study or work, if you have any questions, you can leave a message and exchange, thank you for your support.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report