Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt for Python
  4. Run pyqt5 on docker with ui file

Run pyqt5 on docker with ui file

Scheduled Pinned Locked Moved Unsolved Qt for Python
pythonqt for python
4 Posts 3 Posters 4.3k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • E Offline
    E Offline
    eranp03
    wrote on last edited by eranp03
    #1

    How to run simple python code that open UI file in a Windows container on Docker
    Paython:

    from PyQt5.QtWidgets import QMainWindow, QApplication
    from PyQt5 import uic
    import sys
    
    
    class Ui(QMainWindow):
        def __init__(self):
            super(Ui, self).__init__()
            uic.loadUi('mainWindow.ui', self)
            self.show()
    
    app = QApplication(sys.argv)
    window = Ui()
    app.exec_()
    

    Dockerfile:

    # set base image (host OS)
    FROM python:3.7
    
    # set the working directory in the container
    WORKDIR /code
    
    # copy the dependencies file to the working directory
    COPY requirements.txt .
    
    # install dependencies
    RUN pip install -r requirements.txt
    
    # copy the content of the local src directory to the working directory
    COPY / .
    
    # command to run on container start
    CMD [ "python", "./main.py" ]
    

    requirements file:

    PyQt5==5.15.2
    PyQt5-sip==12.8.1
    

    the Docker build command

    docker built -t myimage .
    

    run the docker command:

    docker run -e DISPLAY="My IP":0 -p 5000:5000 myimage
    

    when I go to "127.0.0.1:5000" this is not working how to fix this?

    JonBJ 1 Reply Last reply
    0
    • E eranp03

      How to run simple python code that open UI file in a Windows container on Docker
      Paython:

      from PyQt5.QtWidgets import QMainWindow, QApplication
      from PyQt5 import uic
      import sys
      
      
      class Ui(QMainWindow):
          def __init__(self):
              super(Ui, self).__init__()
              uic.loadUi('mainWindow.ui', self)
              self.show()
      
      app = QApplication(sys.argv)
      window = Ui()
      app.exec_()
      

      Dockerfile:

      # set base image (host OS)
      FROM python:3.7
      
      # set the working directory in the container
      WORKDIR /code
      
      # copy the dependencies file to the working directory
      COPY requirements.txt .
      
      # install dependencies
      RUN pip install -r requirements.txt
      
      # copy the content of the local src directory to the working directory
      COPY / .
      
      # command to run on container start
      CMD [ "python", "./main.py" ]
      

      requirements file:

      PyQt5==5.15.2
      PyQt5-sip==12.8.1
      

      the Docker build command

      docker built -t myimage .
      

      run the docker command:

      docker run -e DISPLAY="My IP":0 -p 5000:5000 myimage
      

      when I go to "127.0.0.1:5000" this is not working how to fix this?

      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by
      #2

      @eranp03 said in Run pyqt5 on docker with ui file:

      this is not working

      What does not work? There is no error message anywhere? How is docker at issue here?

      1 Reply Last reply
      0
      • E Offline
        E Offline
        eranp03
        wrote on last edited by eranp03
        #3

        @JonB
        There is no error message on CMD
        cmd docker running
        only when I try to get

        localhost:5000
        

        localhost

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Hi,

          Your application does not run a web server therefore trying to access it with a web browser won't work.

          You will have to have a X11 server running on your Windows machine.

          See this article for an explanation about that.

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved