Tensorflow 1.14+:Docker镜像无法按预期工作

时间:2019-10-16 18:52:20

标签: python docker tensorflow docker-compose jupyter-notebook

我正在尝试使用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 builddocker-compose up成功(如果CMD中的Dockerfile被注释掉了),但是退出了。我以为从docker hub repository开始,添加音量将自动启动笔记本。

尝试运行jupyter-notebookjupyter notebook失败。

关于如何纠正的想法?

2 个答案:

答案 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