Docker的上手(Ubuntu140.4 Mate)
首先按照官網運行https://docs.docker.com/engine/installation/linux/ubuntu/#prerequisites
然后不知道怎么用,然后需要
安裝Docker-Compose(需要先安裝docker)
1.?Go to the Compose repository release page on GitHub.
2.?Follow the instructions from the release page and run the curl command, which the release page specifies, in your terminal.
【“Permission denied” ?Run sudo -i, then the two commands below, then exit.】
3.?An example command illustrating the format,Apply executable permissions to the binary.Test the installation.
| 1 2 | curl -L https://github.com/docker/compose/releases/download/1.8.1/docker-compose-`uname-s`-`uname -m` > /usr/local/bin/docker-compose chmod +x /usr/local/bin/docker-compose<br>docker-compose --version |
?
Alternative install options
Install using pip
pip version 6.0 or greater is required
| 1 | pip installdocker-compose |
Install as a container
| 1 2 | curl -L https://github.com/docker/compose/releases/download/1.8.0/run.sh > /usr/local/bin/docker-compose chmod +x /usr/local/bin/docker-compose |
最后就可以使用docker了,具體按照下面我轉載的一篇博文
本次主要是詳細記錄Docker1.12在Ubuntu16.04上的安裝過程,創建Docker組(避免每次敲命令都需要sudo),Docker常用的基本命令的總結,在容器中運行Hello world,以及創建一個基于Python Flask的web應用容器的全過程。
1.Docker1.12在Ubuntu16.04上安裝
1.1.先決條件1,添加Docker源
wxl@wxl-pc:~$ sudo apt-get update- 1
- 2
- 1
- 2
增加CA證書
wxl@wxl-pc:~$ sudo apt-get install apt-transport-https ca-certificates- 1
- 1
添加GPG Key(一種加密手段)
wxl@wxl-pc:~$ sudo apt-key adv --keyserver hkp://p80.pool.sks-keyservers.net:80 --recv-keys 58118E89F3A912897C070ADBF76221572C52609D- 1
- 1
創建docker.list文件
wxl@wxl-pc:~$ sudo vim /etc/apt/sources.list.d/docker.list #添加Ubuntu16.04LST的入口 deb https://apt.dockerproject.org/repo ubuntu-xenial main- 1
- 2
- 3
- 1
- 2
- 3
再次更新源
wxl@wxl-pc:~$ sudo apt-get update- 1
- 2
- 1
- 2
以防萬一,清除過時的源
wxl@wxl-pc:~$ sudo apt-get purge lxc-docker- 1
- 1
驗證下APT是從正確的庫源下載應用的
wxl@wxl-pc:~$ apt-cache policy docker-engine- 1
- 1
至此,可見已經配置好了Docker的源
1.2.先決條件2,安裝aufs驅動linux-image-extra
For Ubuntu Trusty, Wily, and Xenial, it’s recommended to install the Linux-image-extra kernel package. The linux-image-extra package allows you use the aufs storage driver可以實現容器間可執行文件和運行庫的共享。
更新源,會發現Hit:9 https://apt.dockerproject.org/repo ubuntu-xenial InRelease,也說明Docker在第一步1設置成功。
wxl@wxl-pc:~$ sudo apt-get update- 1
- 2
- 1
- 2
安裝 linux-image-extra
wxl@wxl-pc:~$ sudo apt-get install linux-image-extra-$(uname -r)- 1
- 1
1.3.安裝Docker(如果先決條件1,2步正確完成了)
更新源
wxl@wxl-pc:~$ sudo apt-get update- 1
- 1
通過apt命令在線安裝docker
wxl@wxl-pc:~$ sudo apt-get install docker-engine- 1
- 1
開啟docker的守護進程(Docker服務開啟)
wxl@wxl-pc:~$ sudo service docker start- 1
- 1
國際慣例,用一個Hello world的來測試安裝成功
wxl@wxl-pc:~$ sudo docker run hello-world- 1
- 1
本地本來沒有Hello World鏡像,通過Docker源獲取到,并成功現實Hello world。
查看正在運行的容器
- 1
- 1
1.4.創建Docker用戶組,避免使用sudo
如第一步最后“查看正在運行的容器”如果沒有sudo,不以root身份權限運行查看容器命令則會報錯Cannot connect to the Docker daemon. Is the docker daemon running on this host?如圖
原因:
The docker daemon binds to a Unix socket instead of a TCP port. By default that Unix socket is owned by the user root and other users can access it with sudo. For this reason, docker daemon always runs as the root user.
To avoid having to use sudo when you use the docker command, create a Unix group called docker and add users to it. When the docker daemon starts, it makes the ownership of the Unix socket read/writable by the docker group.
創建用戶組docker,可以避免使用sudo
將docker和wxl(王小雷用戶名,在創建主機時默認用戶名稱是ubuntu)添加到一個組內
- 1
- 2
- 3
- 4
- 1
- 2
- 3
- 4
注意需要重新啟動計算機或者注銷用戶再登入,才能生效。這樣就不需要使用sudo命令了。
那么,如何將wxl從docker用戶組移除?
sudo gpasswd -d wxl docker
如何刪除剛才創建的docker用戶組?
sudo groupdel docker
如何創建和刪除新用戶,如用戶newuser
sudo adduser newuser
sudo userdel newuser
1.5.如何更新Docker
wxl@wxl-pc:~$ sudo apt-get upgrade docker-engine- 1
- 1
1.6.如何卸載Docker
wxl@wxl-pc:~$ sudo apt-get purge docker-engine- 1
- 1
2.運行一個web應用–Python Flask
2.1.docker簡單命令匯總如下:
- docker run ubuntu /bin/echo “hello world” -運行ubuntu鏡像并且在命令窗口輸出”hello world”
- docker run -t -i ubuntu /bin/bash -進入ubuntu這個鏡像的bash命令窗口,可以操作本鏡像ubuntu的命令如ls
- docker ps - 列出當前運行的容器
- docker logs - 展示容器的標準的輸出(比如hello world)
- docker stop - 停止正在運行的容器
- docker version -可以查看守護的進程,docker版本以及go版本(docker本身是用go語言寫的)
總結,可以看出docker的命令一般為
[sudo] docker [subcommand] [flags] [arguments]
如docker run -i -t ubuntu /bin/bash
2.2.開始運行Python Flask
運行Python Flask應用(這個過程可能很慢,根據網速而定,因為如果本地沒有鏡像training/webapp:latest會自動線上獲取)
完成
查看運行中打容器通過 docker ps -l
注意:查看你打端口號,可能和我打不一樣
我的是(把Terminal最大化容易識別)
指定端口號,通過Docker -p,如將32769更改為5000
瀏覽器訪問 http://localhost:80 或者http://localhost/
根據Container ID 或者 NAMES 來使用log和top命令,如我執行時產生的CONTAINER ID是83442361e61b,而NAMES是reverent_saha
# 按Ctrl+c結束 查看log wxl@wxl-pc:~$ docker logs -f reverent_saha- 1
- 2
- 1
- 2
- 1
- 1
- 1
- 2
- 3
- 4
- 1
- 2
- 3
- 4
開啟/刪除/當前的web應用容器
#關閉reverent_saha名稱為的web應用容器wxl@wxl-pc:~$ docker start reverent_saha #刪除reverent_saha名稱為的web應用容器(注意,容器必須是stop狀態) wxl@wxl-pc:~$ docker rm reverent_saha- 1
- 2
- 3
- 4
- 5
- 1
- 2
- 3
- 4
- 5
關閉web應用容器,通過docker ps -l 查看容器開啟狀態
wxl@wxl-pc:~$ docker stop reverent_saha #開啟reverent_saha名稱為的web應用容器 wxl@wxl-pc:~$ docker ps -l- 1
- 2
- 3
- 1
- 2
- 3
此時,在打開 http://localhost/ 已經無法鏈接,因為停止來python flask的web應用。
感謝 王小雷-多面手算一個簡單了解吧
概述:基于Docker的TensorFlow機器學習框架搭建和實例源碼解讀,TensorFlow作為最火熱的機器學習框架之一,Docker是的容器,可以很好的結合起來,為機器學習或者科研人員提供便捷的機器學習開發環境,探索人工智能的奧秘,容器隨開隨用方便快捷。源碼解析TensorFlow容器創建和示例程序運行,為熱愛機器學者降低學習難度。
默認機器已經裝好了Docker(Docker安裝和使用可以看我另一篇博文:Ubuntu16.04安裝Docker1.12+開發實例+hello world+web應用容器)。
1.下載TensorFlow鏡像
docker pull tensorflow/tensorflow #或者 #sudo docker pull tensorflow/tensorflow- 1
- 2
- 3
- 1
- 2
- 3
2.創建TensorFlow容器,源碼解讀
docker run --name xiaolei-tensortflow -it -p 8888:8888 -v ~/tensorflow:/notebooks/data tensorflow/tensorflow- 1
- 1
- docker run運行鏡像,
- --name為容器創建別名,
- -it保留命令行運行,
- -p 8888:8888將本地的8888端口http://localhost:8888/映射,
- -v ~/tensorflow:/notebooks/data 將本地的~/tensorflow文件夾掛載到新建容器的/notebooks/data下(這樣創建的文件可以保存到本地~/tensorflow)
- tensorflow/tensorflow為指定的鏡像,默認標簽為latest(即tensorflow/tensorflow:latest)
3.開啟TensorFlow容器
3.1.可以直接從命令行中右鍵打開連接,或者在瀏覽器中輸入localhost:8888,然后將命令行中的token粘貼上去。
4.開始TensorFlow編程(Python語言)
4.1.在首頁可以New一個Python項目
4.2.tensorflow示例源碼解讀
from __future__ import print_function #導入tensorflow import tensorflow as tf #輸入兩個數組,input1和input2然后相加,輸出結果 with tf.Session():input1 = tf.constant([1.0, 1.0, 1.0, 1.0])input2 = tf.constant([2.0, 2.0, 2.0, 2.0])output = tf.add(input1, input2)result = output.eval()print("result: ", result)- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
4.3.運行程序,輸出的結果為(運行成功)
result: [ 3. 3. 3. 3.]- 1
- 1
5.其他 linux,TensorFlow,Docker相關操作
5.1.關閉TensorFlow和開啟TensorFlow環境
#關閉tensorflow容器 docker stop xiaolei-tensortflow#開啟TensorFlow容器 docker start xiaolei-tensortflow #瀏覽器中輸入 http://localhost:8888/- 1
- 2
- 3
- 4
- 5
- 6
- 1
- 2
- 3
- 4
- 5
- 6
5.2.解決文件的讀寫權限
#查看讀寫權限 ls -l #將tensorflow 變為屬于xiaolei(系統默認)用戶 sudo chown -R xiaolei tensorflow/ #將tensorflow 變為屬于xiaolei(系統默認)用戶組 sudo chgrp -R xiaolei tensorflow/總結
以上是生活随笔為你收集整理的Docker的上手(Ubuntu140.4 Mate)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 提供TOR的使用方式
- 下一篇: EPG开发《异常排查以及解决方案》