安裝DOCKERpython
1. https://docs.docker.com/engine/installation/linux/docker-ce/ubuntu/linux
If you cannot use Docker’s repository to install Docker CE, you can download the .deb
file for your release and install it manually. You will need to download a new file each time you want to upgrade Docker CE.git
Go to https://download.docker.com/linux/ubuntu/dists/, choose your Ubuntu version, browse to pool/stable/
and choose amd64
,armhf
, or s390x
. Download the .deb
file for the Docker version you want to install.github
Note: To install an edge package, change the word
stable
in the URL toedge
. Learn about stable and edge channels.web
Install Docker CE, changing the path below to the path where you downloaded the Docker package.sql
$ sudo dpkg -i /path/to/package.deb
The Docker daemon starts automatically.docker
Verify that Docker CE is installed correctly by running the hello-world
image.shell
$ sudo docker run hello-world
This command downloads a test image and runs it in a container. When the container runs, it prints an informational message and exits.flask
Docker CE is installed and running. You need to use sudo
to run Docker commands. Continue to Post-installation steps for Linux to allow non-privileged users to run Docker commands and for other optional configuration steps.ubuntu
2. https://github.com/widuu/chinese_docker/blob/master/installation/ubuntu.md#Ubuntu%E5%AE%89%E8%A3%85Docker
##Ubuntu Docker可選配置
這部分主要介紹了 Docker 的可選配置項,使用這些配置可以讓 Docker 在 Ubuntu 上更好的工做。
###建立 Docker 用戶組
docker 進程經過監聽一個 Unix Socket 來替代 TCP 端口。在默認狀況下,docker 的 Unix Socket屬於root
用戶,固然其餘用戶可使用sudo
方式來訪問。由於這個緣由, docker 進程就一直是root
用戶運行的。
爲了在使用 docker
命令的時候前邊再也不加sudo
,咱們須要建立一個叫 docker
的用戶組,而且爲用戶組添加用戶。而後在 docker
進程啓動的時候,咱們的 docker
羣組有了 Unix Socket 的全部權,能夠對 Socket 文件進行讀寫。
注意:
docker
羣組就至關於root用戶。有關係統安全影響的細節,請查看 Docker 進程表面攻擊細節
建立 docker
用戶組並添加用戶
使用具備sudo
權限的用戶來登陸你的Ubuntu。
在這過程當中,咱們假設你已經登陸了Ubuntu。
建立 docker
用戶組並添加用戶。
$ sudo usermod -aG docker ubuntu
註銷登陸並從新登陸
這裏要確保你運行用戶的權限。
驗證 docker
用戶不使用 sudo
命令開執行 Docker
$ docker run hello-world
建立用戶組docker,能夠避免使用sudo
將docker和wxl(王小雷用戶名,在建立主機時默認用戶名稱是ubuntu)添加到一個組內
#默認是ubuntu用戶 #wxl@wxl-pc:~$ sudo usermod -aG docker ubuntu # 將wxl的用戶添加到docker用戶組中,若是多個用戶須要用空格隔開 如 wxl wxl1 wxl2用戶 wxl@wxl-pc:~$ sudo usermod -aG docker wxl
注意須要從新啓動計算機或者註銷用戶再登入,才能生效。這樣就不須要使用sudo命令了。
那麼,如何將wxl從docker用戶組移除?
sudo gpasswd -d wxl docker
如何刪除剛纔建立的docker用戶組?
sudo groupdel docker
如何建立和刪除新用戶,如用戶newuser
sudo adduser newuser
sudo userdel newuser
###調整內存和交換空間(swap accounting)
當咱們使用 Docker 運行一個鏡像的時候,咱們可能會看到以下的信息提示:
WARNING: Your kernel does not support cgroup swap limit. WARNING: Your kernel does not support swap limit capabilities. Limitation discarded.、
爲了防止以上錯誤信息提示的出現,咱們須要在系統中啓用內存和交換空間。咱們須要修改系統的 GUN GRUB (GNU GRand Unified Bootloader) 來啓用內存和交換空間。開啓方法以下:
使用具備sudo
權限的用戶來登陸你的Ubuntu。
編輯 /etc/default/grub
文件
設置 GRUB_CMDLINE_LINUX
的值以下:
GRUB_CMDLINE_LINUX="cgroup_enable=memory swapaccount=1"
保存和關閉文件
更新 GRUB
$ sudo update-grub
重啓你的系統。
wxl@wxl-pc:~$ sudo apt-get upgrade docker-engine
wxl@wxl-pc:~$ sudo apt-get purge docker-engine
總結,能夠看出docker的命令通常爲
[sudo] docker [subcommand] [flags] [arguments]
如docker run -i -t ubuntu /bin/bash
https://github.com/NVIDIA/nvidia-docker
DOCKER_OPTS="--graph=/home/docker"
service docker restart
[plain] view plain copy
You need at least a 384.xx series driver for CUDA 9. NVIDIA recommends 384.81 or later. If you're installing from deb packages, note that the package name is different for nvidia-384 versus nvidia-375 in order that the major driver version upgrade is intentional rather than automatic.
Alternatively, you can also use a CUDA 8.0 image and not upgrade your driver:
nvidia-docker run --rm nvidia/cuda:8.0-devel nvidia-smi
# Install docker
curl -sSL https://get.docker.com/ | sh
The docker container needs access to the GPU devices. For this purpose use `nvidia-docker` which is a wrapper around the standard `docker` command.
# Install nvidia-docker and nvidia-docker-plugin
wget -P /tmp https://github.com/NVIDIA/nvidia-docker/releases/download/v1.0.0-rc.3/nvidia-docker_1.0.0.rc.3-1_amd64.deb
sudo dpkg -i /tmp/nvidia-docker*.deb && rm /tmp/nvidia-docker*.deb
# Test nvidia-smi.
nvidia-docker run --rm nvidia/cuda nvidia-smi
You might need to use `nvidia-docker` with sudo!
安裝Tensorflow
http://blog.csdn.net/cq361106306/article/details/54094517
http://blog.csdn.net/freewebsys/article/details/70237003
http://blog.csdn.net/dream_an/article/details/55520205
docker pull daocloud.io/daocloud/tensorflow:0.11.0-gpu
先查下你有幾個GPU設備
[root@XXX ~]# ls -la /dev | grep nvidia crw-rw-rw-. 1 root root 195, 0 Sep 16 13:49 nvidia0 crw-rw-rw-. 1 root root 195, 255 Sep 16 13:49 nvidiactl crw-rw-rw-. 1 root root 247, 0 Sep 16 13:54 nvidia-uvm
而後再查你的docker鏡像
y@y:~$ sudo docker images [sudo] password for y: REPOSITORY TAG IMAGE ID CREATED SIZE daocloud.io/daocloud/tensorflow 0.11.0-gpu dd645f420f1d 8 weeks ago 2.713 GB daocloud.io/daocloud/tensorflow 0.10.0-devel-gpu fa886c09638d 3 months ago 5.014 GB hello-world
而後就能夠啓動咯
sudo docker run -ti -v /home/:/mnt/home --privileged=true --device /dev/nvidia0:/dev/nvidia0 --device /dev/nvidiactl:/dev/nvidiactl --device /dev/nvidia-uvm:/dev/nvidia-uvm daocloud.io/daocloud/tensorflow:0.11.0-gpu /bin/bash
上面這句有點長把它寫到docker.sh文件,而後
sh docker.sh
完成。 上面的意思是把本地的/home映射到docker的/mnt目錄
以及各類顯卡設備也映射進去
sudo docker ps -l y@y:~$ sudo docker ps -l CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES a1f2ac36a2c9 daocloud.io/daocloud/tensorflow:0.11.0-gpu "/bin/bash" 10 minutes ago Up 10 minutes 6006/tcp, 8888/tcp
把a1f2ac36a2c9這個名字記住
而後
docker commit a1f2ac36a2c9 新名字
OK了
1. https://medium.com/@gooshan/for-those-who-had-trouble-in-past-months-of-getting-google-s-tensorflow-to-work-inside-a-docker-9ec7a4df945b
The container itself is started as pointed out in the official documentation as follows:
# Run container
nvidia-docker run -d --name <some name> -p 8888:8888 -p 6006:6006 gcr.io/tensorflow/tensorflow:latest-gpu
# Log in
nvidia-docker exec -it <some name> bash
e.g.:
nvidia-docker run -d --name tf1 -p 8888:8888 -p 6006:6006 gcr.io/tensorflow/tensorflow:latest-gpu
nvidia-docker exec -it tf1 bash
Note: Port 8888 is for ipython notebooks and port 6006 is for TensorBoard.
You can test if everything is alright by running this Python script.
https://www.tensorflow.org/install/install_linux#InstallingDocker
GPU support
Prior to installing TensorFlow with GPU support, ensure that your system meets all NVIDIA software requirements. To launch a Docker container with NVidia GPU support, enter a command of the following format:
$ nvidia-docker run -it -p hostPort:containerPort TensorFlowGPUImage
where:
containerPort
to 8888
.We recommend installing one of the latest
versions. For example, the following command launches the latest TensorFlow GPU binary image in a Docker container from which you can run TensorFlow programs in a shell:
$ nvidia-docker run -it gcr.io/tensorflow/tensorflow:latest-gpu bash
The following command also launches the latest TensorFlow GPU binary image in a Docker container. In this Docker container, you can run TensorFlow programs in a Jupyter notebook:
$ nvidia-docker run -it -p 8888:8888 gcr.io/tensorflow/tensorflow:latest-gpu
The following command installs an older TensorFlow version (0.12.1):
$ nvidia-docker run -it -p 8888:8888 gcr.io/tensorflow/tensorflow:0.12.1-gpu
Docker will download the TensorFlow binary image the first time you launch it. For more details see the TensorFlow docker readme.
You should now validate your installation.
使用:Docker
http://songhuiming.github.io/pages/2017/02/25/an-zhuang-dockerhe-tensorflow/
4.0. 下載鏡像
docker pull image-name
4.1. 查看本地鏡像
docker images
4.2. 查看運行的容器
查看active鏡像: docker ps
查看全部鏡像: docker ps -a
查看最近的鏡像: docker ps -l
4.3. 刪除鏡像 刪除容器
docker rmi image-name
docker rm <container id>
4.4. 在repo裏搜索鏡像
docker search [image-name]
4.5. 中止鏡像
docker stop container-id
4.6. 中止並刪除全部容器
docker stop $(docker ps -a -q)
docker rm $(docker ps -a -q)
5.4. 退出
exit
To restart the exited container:
docker start -a -i `docker ps -q -l`
docker start start a container (requires name or ID)
-a attach to container
-i interactive mode
docker ps List containers
-q list only container IDs
-l list only last created container
5.5. How do I install new libraries in Docker?
Therre are two ways to do this:
First methodd: Modify the Dockerfile
directly to install new or update your existing libraries. You will need to do a docker build
after you do this. If you just want to update to a newer version of the DL framework(s), you can pass them as CLI parameter
using the --build-arg tag
(see for details). The framework versions are defined at the top of the Dockerfile
. For example, docker build -t shmhub/dl-docker:cpu -f Dockerfile.cpu --build-arg TENSORFLOW_VERSION=1.2.0 .
Second mthodd: you can install or upgrade in the container. After it is done, exit the cocntainer and do a commit
as introducte below.
5.5. 向docker image提交container change
docker commit -m "install vim wget on ubuntu" -a "author: shm" 7de2c97f7a85 shm/ubuntu_custom
這裏7de2c97f7a85是image id.也就是在bash下面看到的root@後面的id: root@7de2c97f7a85
. 這時候比較先後的鏡像,就會發現commit之後多了一個鏡像
shm@ubuntu:~$ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
tensorflow/tensorflow latest ea40dcc45724 2 weeks ago 1.03 GB
ubuntu latest f49eec89601e 5 weeks ago 129 MB
shm@ubuntu:~$ docker commit -m "install vim wget on ubuntu" -a "author: shm" 7de2c97f7a85 shm/ubuntu_custom
sha256:5ed742f690e11c65db83936847c7c5659c5834f6b2c93b52d110455936e6a224
shm@ubuntu:~$ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
shm/ubuntu_custom latest 5ed742f690e1 12 seconds ago 647 MB
tensorflow/tensorflow latest ea40dcc45724 2 weeks ago 1.03 GB
ubuntu latest f49eec89601e 5 weeks ago 129 MB
5.6. 向倉庫提交鏡像
首先登錄
docker login -u docker-username
而後push
5.6.1. list the image and get the tag id
shm@shm-xps9550:~/projects/dl_lessons/courses-master/deeplearning1/nbs$ `docker images`
REPOSITORY TAG IMAGE ID CREATED SIZE
shmhub/dl-docker cpu 0f1e40d1bed8 12 days ago 9.13 GB
ubuntu 16.04 6a2f32de169d 13 days ago 117 MB
5.6.2. tag the giage with the registoryhost
docker tag 0f1e40d1bed8 pinseng/dl-docker
5.6.3. push the image to the repo
docker push docker-username/docker-image-name
docker push pinseng/dl-docker
除了上面幾種作法以外,docker在1.3.X版本以後還提供了一個新的命令exec用於進入容器,這種方式相對更簡單一些,下面咱們來看一下該命令的使用:
接下來咱們使用該命令進入一個已經在運行的容器
如何獲取localhost的地址?
打開一個新的terminal,查看container的地址:
sudo docker inspect clever_bohr | grep IPAddress
這裏的clever_bohr爲該正在運行的container的名字,例子以下
在瀏覽器中輸入:172.17.0.6:8888
http://blog.csdn.net/tina_ttl/article/details/51417358
http://[all ip addresses on your system]:8888/==========================>http://172.17.0.2:8888/
=========================================================================================================================================================================================================2017/11/8更=====
docker pull tensorflow/tensorflow:nightly-gpu-py3
======================================docker run bash版本========================================
===========================================================本地ipython3 notebook=================================================
=======================================================make password==================================================
========================================================use docker-tf jupyter .sh code========================================================