周六上午起来试了试Docker 运行tensorflow
因为昨天已经pull好了镜像,只需要创建容器。
[root@compute ~]# docker run --name lzb-tensorflow -it -p 8888:8888 -v ~/tensorflow:/test/data tensorflow/tensorflow
________ _______________
___ __/__________________________________ ____/__ /________ __
__ / _ _ \_ __ \_ ___/ __ \_ ___/_ /_ __ /_ __ \_ | /| / /
_ / / __/ / / /(__ )/ /_/ / / _ __/ _ / / /_/ /_ |/ |/ /
/_/ \___//_/ /_//____/ \____//_/ /_/ /_/ \____/____/|__/
WARNING: You are running this container as root, which can cause new files in
mounted volumes to be created as the root user on your host machine.
To avoid this, run the container by specifying your user's userid:
$ docker run -u $(id -u):$(id -g) args...
root@811c61aa3b7d:/# ll
创建是创建好了,怎么没有显示URL??于是我就exit退出了
退出之后查看所有容器
[root@compute ~]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
811c61aa3b7d tensorflow/tensorflow "/bin/bash" 7 minutes ago Exited (127) 5 minutes ago lzb-tensorflow
16afcba0e6e6 hello-world "/hello" 9 hours ago Exited (0) 9 hours ago jolly_noyce
可以看到上面tensorflow容器是非运行状态Exited
这时执行下面指令进入容器,是进不去的
[root@compute ~]# docker exec -i -t 811c61aa3b7d /bin/bash
Error response from daemon: Container 811c61aa3b7d44d18298f8a29a7d6644462c91624eb3f233db8a37f12dc7918b is not running
这说明容器已经启动过了,重新start一下,再进入容器即可
[root@compute ~]# docker start 811c61aa3b7d
811c61aa3b7d
这时再查看一下所有容器,可以看到tf已经起来了(up)
[root@compute ~]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
811c61aa3b7d tensorflow/tensorflow "/bin/bash" 18 minutes ago Up 3 minutes 0.0.0.0:8888->8888/tcp lzb-tensorflow
16afcba0e6e6 hello-world "/hello" 10 hours ago Exited (0) 10 hours ago jolly_noyce
再次进入容器,进来了
[root@compute ~]# docker exec -i -t 811c61aa3b7d /bin/bash
________ _______________
___ __/__________________________________ ____/__ /________ __
__ / _ _ \_ __ \_ ___/ __ \_ ___/_ /_ __ /_ __ \_ | /| / /
_ / / __/ / / /(__ )/ /_/ / / _ __/ _ / / /_/ /_ |/ |/ /
/_/ \___//_/ /_//____/ \____//_/ /_/ /_/ \____/____/|__/
WARNING: You are running this container as root, which can cause new files in
mounted volumes to be created as the root user on your host machine.
To avoid this, run the container by specifying your user's userid:
$ docker run -u $(id -u):$(id -g) args...
root@811c61aa3b7d:/#
关闭容器
[root@compute ~]# docker stop 811
811
[root@compute ~]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
811c61aa3b7d tensorflow/tensorflow "/bin/bash" About an hour ago Exited (0) 3 seconds ago lzb-tensorflow
16afcba0e6e6 hello-world "/hello" 10 hours ago Exited (0) 10 hours ago jolly_noyce
再次开启容器
[root@compute ~]# docker start 811
811
[root@compute ~]# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
811c61aa3b7d tensorflow/tensorflow "/bin/bash" About an hour ago Up 2 seconds 0.0.0.0:8888->8888/tcp lzb-tensorflow
16afcba0e6e6 hello-world "/hello" 10 hours ago Exited (0) 10 hours ago jolly_noyce
查看一下这个环境的操作系统
root@811c61aa3b7d:/# cat /etc/lsb-release
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=18.04
DISTRIB_CODENAME=bionic
DISTRIB_DESCRIPTION="Ubuntu 18.04.4 LTS"
没有jupyter,就进入命令行吧
root@811c61aa3b7d:/# python
Python 3.6.9 (default, Jul 17 2020, 12:50:27)
[GCC 8.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import tensorflow as tf
2020-08-14 19:44:22.266912: W tensorflow/stream_executor/platform/default/dso_loader.cc:59] Could not load dynamic library 'libcudart.so.10.1'; dlerror: libcudart.so.10.1: cannot open shared object file: No such file or directory
2020-08-14 19:44:22.266941: I tensorflow/stream_executor/cuda/cudart_stub.cc:29] Ignore above cudart dlerror if you do not have a GPU set up on your machine.
用如下代码可检测tensorflow的能使用设备情况:
from tensorflow.python.client import device_lib
print(device_lib.list_local_devices())
输出
[name: "/device:CPU:0"
device_type: "CPU"
memory_limit: 268435456
locality {
}
incarnation: 17125062641778436069
, name: "/device:XLA_CPU:0"
device_type: "XLA_CPU"
memory_limit: 17179869184
locality {
}
incarnation: 8488404382051035286
physical_device_desc: "device: XLA_CPU device"
]