2

I'm trying to run an image with a pygame script, but i get the error: pygame.error: No available video device

The pygame script works good on my computer (Linux, Ubuntu 16.04, 32 bits, i installed docker using these steps: https://stackoverflow.com/a/48881019/6796652), the problem happens when i include it in the dockerfile image.

I read some posts related as this pygame projects won't run: "pygame.error: No available video device", but i couldn't find the same issue in a dockerfile.

This is a part of the pygame script:

import pygame

def main():
    pygame.init()
    screen=pygame.display.set_mode((400,600))

    # Here are more code...
    # And finally

    pygame.quit()

main() 

I tried including this part, as this post says https://stackoverflow.com/a/53623914/6796652

from pygame.locals import *

This is my Dockerfile:

FROM python:3
WORKDIR /myfolder
COPY main.py someimage.png wallpaper.jpg requirements.txt ./
RUN pip install --no-cache-dir -r requirements.txt
CMD [ "python", "./main.py" ]

I tried also with an Ubuntu image, but the result was exactly the same:

FROM ubuntu:14.04
WORKDIR /myfolder
COPY main.py someimage.png wallpaper.jpg requirements.txt ./
RUN apt-get update
RUN apt-get install python-pip python-dev build-essential -y
RUN pip install --upgrade pip 
RUN pip install --no-cache-dir -r requirements.txt
CMD [ "python", "./main.py" ]

Even, installing dependencies for Python 3.x as the documentation says: http://www.pygame.org/wiki/CompileUbuntu the result was the same

FROM python:3
WORKDIR /DefeatTheBat
COPY bat.png main.py wallpaper.jpg requirements.txt ./
RUN apt-get update && apt-get install -y \
    python3-dev -y \ 
    python3-setuptools -y \ 
    python3-numpy -y \ 
    python3-opengl -y  \ 
    libsdl-image1.2-dev -y \ 
    libsdl-mixer1.2-dev -y \ 
    libsdl-ttf2.0-dev -y \ 
    libsmpeg-dev -y \ 
    libsdl1.2-dev -y \ 
    libportmidi-dev -y \ 
    libswscale-dev -y \ 
    libavformat-dev -y \ 
    libavcodec-dev -y \ 
    libtiff5-dev -y \ 
    libx11-6 -y \ 
    libx11-dev -y \ 
    fluid-soundfont-gm -y \ 
    timgm6mb-soundfont -y \ 
    xfonts-base -y \ 
    xfonts-100dpi -y \ 
    xfonts-75dpi -y \ 
    xfonts-cyrillic -y \ 
    fontconfig -y \ 
    fonts-freefont-ttf -y \ 
    libfreetype6-dev -y
RUN pip install --no-cache-dir -r requirements.txt
CMD [ "python", "./main.py" ]

And the requirements.txt:

pygame==1.9.5

I'm getting this error:

    screen=pygame.display.set_mode((400,600)) 
pygame.error: No available video device

When it should display the windows. If i try that part in my interactive python shell, it works good.

How can i fix this dockerfile image?

Manuel Carrero
  • 599
  • 1
  • 9
  • 29
  • 3
    The type of isolation will not let you have access to display, neither to the host running display management system. Even if some Access can be granted by pointig to proper devices you have to know that primary host system is using IT as well to comunicate with the user – h__ Apr 22 '19 at 19:20
  • @h__ can you be more specific please? That means that it's not possible to run pygame on docker? – Manuel Carrero Apr 24 '19 at 19:56
  • Maybe there is some way to run it from docker, but not in such set-up - maybe you can install some virtual graphic card driver which will stream the video to some remote screen or use some other solution. I'm saying that it is not possible to run it out of the box because of the limitations and design of sandboxing – h__ Apr 25 '19 at 08:55
  • Running `xhost local:root` solved this for me. https://github.com/jessfraz/dockerfiles/issues/6#issuecomment-77789863 – roshambo Jan 26 '22 at 18:46

0 Answers0