create pygame to docker image
#Create a requierements.txt file then write down this until line 11 version: '3' services: app: build: . environment: DISPLAY: 172.20.10.13:0 #this using format DISPLAY: HOST IP:0, so check ur ip address volumes: - /tmp/.X11-unix:/tmp/.X11-unix - .:/usr/src/app #After that, insert this to your dockerfile FROM python:3.10 RUN apt-get update && apt-get install -y python-dev python-setuptools WORKDIR /usr/src/app COPY requirements.txt ./ RUN pip install -r requirements.txt COPY . . CMD ["python", "main.py"] #Then add this to your main.py to check the driver drivers = ['x11', 'directfb', 'fbcon', 'svgalib'] found = False for driver in drivers: if not os.getenv('SDL_VIDEODRIVER'): os.environ['SDL_VIDEODRIVER'] = driver try: pygame.display.init() except pygame.error: print 'Driver: {0} failed.'.format(driver) continue found = True break if not found: raise Exception('No suitable video driver found!') #Then try to build your docker, good luck #Simple docker build and run #don't forget to running your docker desktop first docker image build -t python-game #after finish on build docker run python-game #Source : https://opeonikute.dev/posts/running-pygame-in-a-docker-container-macos https://geekyhumans.com/how-to-run-my-python-script-on-docker/
Source: opeonikute.dev