【问题标题】:Tensorflow 1.14+: docker image doesn't work as expected with docker-composeTensorflow 1.14+:docker 映像无法按预期使用 docker-compose
【发布时间】:2019-10-16 18:52:20
【问题描述】:

我正在尝试使用 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 成功(如果Dockerfile 中的CMD 被注释掉),但只是退出。在docker hub repository 中,我认为添加卷会自动启动笔记本。

尝试运行 jupyter-notebookjupyter notebook 失败。

思考如何改正?

【问题讨论】:

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


    【解决方案1】:

    如果您想从官方添加笔记本目录创建自定义图像,那么 docker-compose 中的图像属性应该是您本地图像的名称而不是 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 上按预期工作。

    【讨论】:

    • 构建是作为故障排除的一部分添加的,这意味着我也尝试过没有。你目前在ERROR: for tf Cannot start service tf: OCI runtime create failed: container_linux.go:346: starting container process caused "exec: \"jupyter notebook --notebook- ...得到的结果
    • 我怀疑您有自己的损坏副本,该副本是使用上述 Dockerfile 在本地以名称 'tensorflow/tensorflow:1.15.0rc2-gpu-py3-jupyter' 构建的。首先运行 docker image rm tensorflow/tensorflow:1.15.0rc2-gpu-py3-jupyter 并从 docker hub 拉取新的 tensorflow/tensorflow:1.15.0rc2-gpu-py3-jupyter 映像。
    【解决方案2】:

    试试这个

    RUN pip3 install nvidia-tensorflow
    

    这将安装 tf 1.15

    【讨论】:

      猜你喜欢
      • 2020-03-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-08-23
      • 1970-01-01
      • 1970-01-01
      • 2019-12-15
      • 1970-01-01
      相关资源
      最近更新 更多