那么上篇博客简单了解了docker的情况,这一篇就来简单的跑点东西玩玩。
首先,linux的环境还是要准备一个的,docker for windows我装了之后不但没有启动成功,还把电脑的虚拟化功能给搞坏了,最后还是搞了个centos的虚拟机。
Docker目前分为了社区版和企业版,通常来说社区版给一些基本功能尝尝鲜,要是好用的话,再向他们买企业版。咱们这种简单的使用社区版已经够用了。
Docker在linux的安装非常简单,执行命令之前,官方建议先把旧版本的docker删除掉。直接用yum install docker装的版本,差了大概3、4个版本的样子。
执行命令
yum remove docker docker-common container-selinux docker-selinux docker-engine
之后,安装docker社区版,社区版的docker源需要我们手动添加一下,这里可能需要安装yum的两个工具,执行命令。
yum install -y yum-utils device-mapper-persistent-data lvm2
然后将,docker社区版的源地址加入yum的repo中。
yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
更新yum的索引。
yum makecache fast
这下可以愉快的安装了。
yum install docker-ce
安装之后,启动docker服务
systemctl start docker
启动没有失败的话,我们可以试试docker官方给的hello-world镜像。
docker run hello-world
本地的服务器现在是没有镜像的,docker会先从服务器上拉取helloworld的镜像,之后会把它运行起来。只要网络没啥问题,基本上就能运行了,这个helloworld就是只是输出了一部分文本,之后这个docker就关闭了。
需要哪些服务的话就用docker search {name}的方式搜索想要的镜像,然后用docker pull {name}的方式下载想要的镜像。
比如我这里
docker search tensorflow
会列出我想要的一些镜像,排在第一位的后面的描述有写是官方的镜像。
NAME DESCRIPTION STARS OFFICIAL AUTOMATED
tensorflow/tensorflow Official docker images for deep learning f... 442
xblaster/tensorflow-jupyter Dockerized Jupyter with tensorflow 39 [OK]
satoshun/tensorflow-notebook Jupyter with Tensorflow 5 [OK]
earthlab/r-tensorflow Docker container with R, RStudio, tensorfl... 4 [OK]
floydhub/tensorflow tensorflow 3 [OK]
chiefware/tensorflow-jupyter tensorflow jupyter image to run under othe... 3 [OK]
bwits/tensorflow-alpine Build tensorflow in alpine 3 [OK]
eboraas/tensorflow TensorFlow with Jupyter Notebook, includin... 2 [OK]
用pull命令拉取镜像,这里复制查询出来的全名最好,省的拼写错误死活下载不到- -
docker pull tensorflow/tensorflow
然后就可以run一哈了。加了几个参数,后台运行,端口映射
docker run -it -d -p 8888:8888 tensorflow/tensorflow
之后返给了我一个docker 的id,查看启动时的日志。
docker logs 54f5feb9cb8fa05e2abf7d675c85b1ec8046d0ec77792b41d56e9705787b7836
显示了启动成功的一些句子。
[I 15:29:03.071 NotebookApp] Writing notebook server cookie secret to /root/.local/share/jupyter/runtime/notebook_cookie_secret
[W 15:29:03.088 NotebookApp] WARNING: The notebook server is listening on all IP addresses and not using encryption. This is not recommended.
[I 15:29:03.097 NotebookApp] Serving notebooks from local directory: /notebooks
[I 15:29:03.097 NotebookApp] 0 active kernels
[I 15:29:03.097 NotebookApp] The Jupyter Notebook is running at: http://[all ip addresses on your system]:8888/?token=ae3878e7f3246ac29ef59610e07f56f4a15c529ac5123b0a
[I 15:29:03.097 NotebookApp] Use Control-C to stop this server and shut down all kernels (twice to skip confirmation).
[C 15:29:03.098 NotebookApp]
Copy/paste this URL into your browser when you connect for the first time,
to login with a token:
http://localhost:8888/?token=ae3878e7f3246ac29ef59610e07f56f4a15c529ac5123b0a
然后,在linux虚拟机中打开这个网址。
哦尅,启动成功了。