1

I am newbie in docker, but I have searched so much about the problem I am facing.

I am having a code in which I am using tensorflow, PyQt and other packages. Now, I have pulled the tensorflow/tensorflow:1.4.0-gpu-py3 and nvidia/cuda:8.0-cudnn6-runtime. Also I have build the image of my application with some dependencies.

I tried to run all the above images with the docker-compose as below:

version: '3'
services:
  nvidia:
    image: "nvidia/cuda:8.0-cudnn6-runtime"

  tensorflow:
    image: "tensorflow/tensorflow:1.4.0-gpu-py3"

  app:
    image: my_app

But I am getting error ImportError: No module named 'tensorflow'.

Please help me by suggesting the way I should solve this.

Edit:

Following code sample is just few lines of my code.

import sys
from PyQt5 import QtCore, QtGui, QtQml, QtQuick
from OpenGL import GL
import cv2 # .cv2 as cv2
from multiprocessing import Process,Queue, Value, Manager
import os
import tensorflow as tf

Edit:

# Use an official Python runtime as a parent image
FROM ubuntu:16.04

# Set the working directory to /app
WORKDIR /app

# Copy the current directory contents into the container at /app
COPY . /app

RUN \
  apt-get update && \
  apt-get install -y python python-dev python-pip python-virtualenv && \
  rm -rf /var/lib/apt/lists/*


RUN apt-get update && apt-get install -y --no-install-recommends apt-utils && apt-get install -y libgtk2.0-dev python python-dev python3 python3-dev python3-pip

RUN apt-get update && apt-get install -y build-essential cmake git libgtk2.0-dev pkg-config libavcodec-dev libavformat-dev libswscale-dev

RUN pip install setuptools pip --upgrade --force-reinstall


# Install any needed packages specified in requirements.txt
RUN pip install --trusted-host pypi.python.org -r requirements.txt

#RUN apt-get update -y

# Install packages
#RUN apt-get install -y curl
#RUN apt-get install -y postgresql
#RUN apt-get install -y postgresql-client
#RUN apt-get install -y python3-numpy python3-opengl python-qt4 python-qt4-gl


# Run app.py when the container launches
CMD ["python3", "Working.py"]

requirement.txt

PyOpenGL
PyQt5
opencv-python
Akhilesh
  • 1,024
  • 1
  • 9
  • 26

1 Answers1

1

You have 3 separate docker containers, Nvidia, Tensorflow, And you application.

When you include tensorflow in python application, there is no Tensorflow package there, it is in separate container.

Suggestion is to remove Tensor-flow container, and add app into tensorflow image.

In you Dockerfile change FROM image:

FROM ubuntu:16.04 to FROM tensorflow/tensorflow:1.4.0-gpu-py3

Then change other parts of Dockerfile installation, because tensorflow image already have python3 installed.

Edmhs
  • 3,645
  • 27
  • 39
  • Thanks @Edmhs , this almost worked for me. I am getting `qt.qpa.screen: QXcbConnection: Could not connect to display Could not connect to any X display.` error – Akhilesh Dec 13 '18 at 11:39
  • This error is related to Display apps, maybe python-qt4, you should research "Running GUI apps with Docker" – Edmhs Dec 14 '18 at 06:51