我正在尝试使用docker和tensorflow测试我的设置。我使用的是官方Tensorflow图片tensorflow/tensorflow:1.15.0rc2-gpu-py3
我的项目具有最小结构:
project/
Dockerfile
docker-compose.yml
jupyter/
README.md
我有以下Dockerfile
:
# from official image
FROM tensorflow/tensorflow:1.15.0rc2-gpu-py3-jupyter
# add my notebooks so they are a part of the container
ADD ./jupyter /tf/notebooks
# copy-paste from tf github dockerfile in attempt to troubleshoot
# https://github.com/tensorflow/tensorflow/tree/master/tensorflow/tools/dockerfiles/dockerfiles/gpu-jupyter.Dockerfile
WORKDIR /tf
RUN which jupyter
CMD ["jupyter-notebook --notebook-dir=/tf/notebooks --ip 0.0.0.0 --no-browser --allow-root"]
和docker-compose.yml
version: '3'
services:
tf:
image: tensorflow/tensorflow:1.15.0rc2-gpu-py3-jupyter
# mount host system volume to save updates from container
volumes:
- jupyter:/tf/notebooks
ports:
- '8888:8888'
# added as part of troubleshooting
build:
context: .
dockerfile: Dockerfile
volumes:
jupyter:
运行docker-compose build
和docker-compose up
成功(如果CMD
中的Dockerfile
被注释掉了),但是退出了。我以为从docker hub repository开始,添加音量将自动启动笔记本。
尝试运行jupyter-notebook
或jupyter notebook
失败。
关于如何纠正的想法?
答案 0 :(得分:1)
如果要通过添加笔记本目录的官方映像创建自定义映像,则docker-compose中的image属性应该是本地映像的名称,而不是tensorflow / tensorflow:1.15.0rc2-gpu-py3 -jupyter。在这种情况下,您需要做的只是以下Dockerfile:
FROM tensorflow/tensorflow:1.15.0rc2-gpu-py3-jupyter
ADD ./jupyter /tf/notebooks
在这种情况下,docker-compose.yaml文件应如下所示:
version: '3'
services:
tf:
image: tensorflow
# mount host system volume to save updates from container
volumes:
- jupyter:/tf/notebooks
ports:
- '8888:8888'
# added as part of troubleshooting
build:
context: .
dockerfile: Dockerfile
volumes:
jupyter:
请注意,图像是张量流。
但是,实际上并不需要使用自定义Dockerfile。只需使用以下docker-compose.yaml文件:
version: '3'
services:
tf:
image: tensorflow/tensorflow:1.15.0rc2-gpu-py3-jupyter
# mount host system volume to save updates from container
volumes:
- ./jupyter:/tf/notebooks:Z
ports:
- '8888:8888'
它将直接将您的本地jupyter目录映射到容器,并使用未经修改的正式映像。
不过请注意,由于主机目录的映射问题,它可能无法在Windows上正常工作。
答案 1 :(得分:0)
试试这个
RUN pip3 install nvidia-tensorflow
这将安装 tf 1.15