国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 服務器 > Web服務器 > 正文

基于docker安裝tensorflow的完整步驟

2024-09-01 13:53:56
字體:
來源:轉載
供稿:網友

前言

google又一次成為大家膜拜的大神了。google大神在引導這機器學習的方向。 同時docker 也是一個非常好的工具,大大的方便了開發環境的構建,之前需要配置安裝。 最近在自學機器學習,大熱的Tensorflow自然不能錯過,所以首先解決安裝問題,為了不影響本地環境,所以本文基于Docker來安裝Tensorflow,我的環境是Ubuntu16.04。

docker,tensorflow,gpu,docker安裝部署

安裝Docker

Docker分為CE和EE,這里我們選擇CE,也就是常規的社區版,首先移除本機上可能存在的舊版本。

移除舊版本

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

安裝可選內核模塊

從Ubuntu14.04以后,某些裁剪后的系統會把一部分內核模塊移到可選內核包中,常以linux-image-extra-*開頭,而Docker推薦的存儲層驅動AUFS包含在可選內核模塊包中,所以還是建議安裝可選內核模塊包的??梢允褂靡韵旅畎惭b:

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

證書及密鑰準備

在正式安裝之前,我們需要添加證書以及HTTPS傳輸的軟件包以保證軟件下載過程中不被篡改:

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

添加軟件源的GPG密鑰:

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

最后添加Docker軟件源:

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

安裝Docker

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

建立docker用戶組

docker通常會使用Unix socket和Docker引擎通訊,通常只有root和docker用戶組的用戶才可以訪問該socket,不然你就要一直sudo,所以最好把你當前需要使用docker的用戶添加到docker用戶組中。

建立docker用戶組

$ sudo groupadd docker

將當前用戶加入用戶組

$ sudo usermod -aG docker $USER

最后重新登錄下系統

測試Docker

確保服務啟動

$ sudo service docker start

使用HelloWorld測試

測試安裝是否成功

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 Docker!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/

若能顯示,證明安裝成功。

安裝Tensorflow

有了Docker,安裝Tensorflow基本沒有什么難度。

下載鏡像

docker pull tensorflow/tensorflow

docker,tensorflow,gpu,docker安裝部署

下載完畢后顯示:

Status: Downloaded newer image for tensorflow/tensorflow:latest

創建Tensorflow容器

docker run --name my-tensorflow -it -p 8888:8888 -v ~/tensorflow:/test/data tensorflow/tensorflow
  • --name:創建的容器名,即my-tensorflow
  • -it:保留命令行運行
  • p 8888:8888:將本地的8888端口和http://localhost:8888/映射
  • -v ~/tensorflow:/test/data:將本地的~/tensorflow掛載到容器內的/test/data下
  • tensorflow/tensorflow :默認是tensorflow/tensorflow:latest,指定使用的鏡像

輸入以上命令后,默認容器就被啟動了,命令行顯示:

[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 15:08:31.975 NotebookApp] Serving notebooks from local directory: /notebooks[I 15:08:31.975 NotebookApp] 0 active kernels[I 15:08:31.975 NotebookApp] The Jupyter Notebook is running at:[I 15:08:31.975 NotebookApp] http://[all ip addresses on your system]:8888/?token=649d7cab1734e01db75b6c2b476ea87aa0b24dde56662a27[I 15:08: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:09:08.581 NotebookApp] 302 GET /?token=649d7cab1734e01db75b6c2b476ea87aa0b24dde56662a27 (172.17.0.1) 0.42ms

拷貝帶token的URL在瀏覽器打開

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

顯示如下:

docker,tensorflow,gpu,docker安裝部署

顯示Jupyter Notebook,Jupyter Notebook(此前被稱為 IPython notebook)是一個交互式筆記本。示例中已經顯示了Tensorflow的入門教程,點開一個可以看見

docker,tensorflow,gpu,docker安裝部署

如上面這個例子,是使用tensorflow來使兩個array相加,我們點擊run,就可以看到運行的結果了。

關閉容器

docker stop my-tensortflow

再次打開

docker start my-tensortflow

如果不喜歡用Jupyter Notebook,我們也可以創建基于命令行的容器

基于命令行的容器

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

這樣我們就創建了名為bash_tensorflow的容器

還是用start命令啟動容器:

docker start bash_tensorflow

再連接上容器:

docker attach bash_tensorflow

可以看到我們用終端連接上了容器,和操作Linux一樣了。

這個鏡像默認沒有裝vim,所以自己又下載了vim來寫代碼。

至此,安裝過程結束。

總結

以上就是這篇文章的全部內容了,希望本文的內容對大家的學習或者工作具有一定的參考學習價值,如果有疑問大家可以留言交流,謝謝大家對VEVB武林網的支持。


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 三门峡市| 和硕县| 兴安县| 彭山县| 涡阳县| 富民县| 台州市| 额尔古纳市| 和田县| 额尔古纳市| 岑巩县| 中卫市| 安多县| 外汇| 九龙城区| 洪洞县| 仁化县| 青浦区| 噶尔县| 南开区| 漯河市| 舒兰市| 贡觉县| 台南市| 昭苏县| 积石山| 宝山区| 蚌埠市| 兰考县| 渑池县| 肇州县| 河东区| 玛纳斯县| 上饶县| 丽江市| 永州市| 思茅市| 思茅市| 云安县| 云安县| 云霄县|