0

I was trying to follow this guide to make a simple python game and decided to use docker to manage the versions and stuff.

but when running the docker image i get the following error:

The path /dev/dri/ cannot be opened or is not available
The path /dev/dri/ cannot be opened or is not available
The path /dev/dri/ cannot be opened or is not available
The path /dev/dri/ cannot be opened or is not available
Traceback (most recent call last):
File "/app/main.py", line 32, in <module>
main()
File "/app/main.py", line 13, in main
with tcod.context.new_terminal(
File "/usr/local/lib/python3.9/site-packages/tcod/_internal.py", line 29, in wrapper
return func(*args, **kwargs)
File "/usr/local/lib/python3.9/site-packages/tcod/context.py", line 616, in 
new_terminal
return new(
File "/usr/local/lib/python3.9/site-packages/tcod/context.py", line 569, in new
_check_warn(error)
File "/usr/local/lib/python3.9/site-packages/tcod/_internal.py", line 75, in 
_check_warn
if _check(error) > 0:
File "/usr/local/lib/python3.9/site-packages/tcod/_internal.py", line 62, in _check
_raise_tcod_error()
File "/usr/local/lib/python3.9/site-packages/tcod/_internal.py", line 56, in 
_raise_tcod_error
raise RuntimeError(ffi.string(lib.TCOD_get_error()).decode("utf-8"))

RuntimeError: libtcod 1.20.1 libtcod/src/libtcod/renderer_sdl2.c:902
Could not initialize SDL:
dummy not available
Video driver 'x11' is not working.
Video driver 'wayland' is not working.
Video driver 'KMSDRM' is not working.
Video driver 'KMSDRM_LEGACY' is not working.
Video driver 'dummy' is not working.

my dockerfile

# syntax=docker/dockerfile:1

FROM python:3.9.0

WORKDIR /app

COPY requirements.txt requirements.txt

RUN python3 -m pip install -r requirements.txt

COPY . .

CMD [ "python3", "main.py", "--host=0.0.0.0"]

the requirements are very simple

tcod
numpy

finally my main.py

#!/usr/bin/env python3
import tcod


def main() -> None:
screen_width = 80
screen_height = 50

tileset = tcod.tileset.load_tilesheet(
    "assets/dejavu10x10_gs_tc.png", 32, 8, tcod.tileset.CHARMAP_TCOD
)

with tcod.context.new_terminal(
    screen_width,
    screen_height,
    tileset=tileset,
    title="Yet Another Roguelike Tutorial",
    vsync=True,
) as context:
    root_console = tcod.Console(screen_width, screen_height, order="F")
    while True:
        root_console.print(x=1, y=1, string="@")

        context.present(root_console)

        for event in tcod.event.wait():
            if event.type == "QUIT":
                raise SystemExit()


if __name__ == "__main__":
    main()

I dont know if it helps but im on ubuntu 20.04

im guessing that it has something to do with the drivers but im not really sure how to solve this since im new to python and docker. i tried using other python versions for the image but it also fails

EDIT: the code works fine outside docker

Talha Tayyab
  • 8,111
  • 25
  • 27
  • 44
Yamil
  • 3
  • 2
  • Does your code work if you run it outside of Docker? – Joseph Sible-Reinstate Monica Jun 19 '22 at 04:06
  • i forgot to add that the code works fine outside docker. so i guess it has something to do with the image – Yamil Jun 19 '22 at 04:39
  • docker doesn't set display by default so you need to specify $DISPLAY by yourself. try https://stackoverflow.com/questions/50326335/display-host-computer-with-tkinter-from-a-python-app-run-on-docker – whilrun Jun 19 '22 at 05:46
  • no luck, i tried running docker with -e DISPLAY=$DISPLAY and i get a different error "docker: Error response from daemon: failed to create shim task: OCI runtime create failed: runc create failed: unable to start container process: exec: "-e": executable file not found in $PATH: unknown." – Yamil Jun 19 '22 at 13:26
  • Docker is built as an isolation system, so it can't access the X display socket, or the authentication data in your host home directory, or the underlying graphics accelerator device, without special setup. I'd recommend running this program outside a container. – David Maze Jun 20 '22 at 13:49

0 Answers0