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?