# Ubuntu 14.04 LTS 安装卸载 Docker 和 Tensorflow
# Ubuntu 安装卸载 Docker Engine 和 Docker Machine
## 前提条件
内核版本应该高于3.10, 使用`uname -r`查看内核版本
## 使用脚本安装Docker
__(脚本安装非常坑爹,很难卸载)__
其实在Ubuntu下一句命令就可以了`sudo apt-get install docker-ce`
### 获取最新版本的Docker安装包
```
wget -qO- https://get.docker.com/ | sh
```
> 据说用这个命令会更快,因为使用了国内镜像,没试过`curl -sSL https://get.daocloud.io/docker | sh`
输入当前用户密码后,将自动下载脚本,安装Docker及其依赖包
安装完成后提示:
```
If you would like to use Docker as a non-root user, you should now consider
adding your user to the "docker" group with something like:
sudo usermod -aG docker username
Remember that you will have to log out and back in for this to take effect!
```
如果要以非root账户运行Docker,需要先执行`sudo usermod -aG username `,并且需要注销重新登录才能生效
### 启动Docker后台服务
```
sudo service docker start
```
测试运行`hello-world`
```
docker run hello-world
```
# 安装Tensorflow
## 添加国内镜像
```
echo "DOCKER_OPTS=\"\$DOCKER_OPTS --registry-mirror=http://f2d6cb40.m.daocloud.io\"" | sudo tee -a /etc/default/docker
sudo service docker restart
```
## pull Tensorflow
```
docker run -it -p 8888:8888 tensorflow/tensorflow
```
真的挺快的
## 安装Docker Machine
[官方安装链接](https://docs.docker.com/machine/install-machine/)
不过在Ubuntu下执行他所说的
```
curl -L https://github.com/docker/machine/releases/download/v0.12.2/docker-machine-`uname -s`-`uname -m` >/tmp/docker-machine &&
chmod +x /tmp/docker-machine &&
sudo cp /tmp/docker-machine /usr/local/bin/docker-machine
```
命令,鬼死甘慢,下不了
搭梯,翻墙,到github上下载,但是`sudo cp`到相应目录重命名后,非root用户执行不了,没有权限,root用户又说找不到命令,于是`sudo chmod`之后解决
## 启动Docker Machine
Docker运行起来需要一些辅助依赖包,比如`virtualbox`(不难理解),因此需要安装`virtualbox`
```
sudo apt-get install virtualbox-qt
```
然后`docker-machine create -d virtualbox default`
第一次创建会很慢,因为据说需要下载一系列的引导之类,天朝的网络,你懂的
过程中需要下载一个`boot2docker.iso`,很慢,去[这里](https://github.com/boot2docker/boot2docker/releases)直接下载下来,放到`/home/shawn/.docker/machine/cache`目录下,`Ctrl+C`掉命令,重新执行,就很nice了,`docker-machine ls`可以看到已经跑起来了
[参考博文](http://blog.csdn.net/pipisorry/article/details/50921335)
## 卸载Docker
[参考](https://stackoverflow.com/questions/31313497/how-to-remove-docker-installed-using-wget)
```
sudo apt-get purge -y docker-ce
sudo apt-get autoremove -y --purge docker-ce
sudo apt-get autoclean
```
It adds:
The above commands will not remove images, containers, volumes, or user created configuration files on your host. If you wish to delete all images, containers, and volumes run the following command:
```
sudo rm -rf /var/lib/docker
```
Remove docker from apparmor.d:
```
sudo rm /etc/apparmor.d/docker
```
Remove docker group:
```
sudo groupdel docker
```
__卸载重新安装Docker后,docker-machine需要重新注册Docker daemon__
```
docker-machine regenerate-certs [VM name]
```