Hi, I try to automate some tasks by using pyinput and pyautogui. Now I wanna pack everything in a Docker container to that a friend can also run the code. The code is as follows in the file myfile.py:
import random
import time
import pyautogui
from pynput.mouse import Button, Controller
mouse = Controller()
xValue = 470
yValue = 400
time.sleep(5)
for i in range(4):
sleepafterdoubleclick = random.uniform(0.4, 0.7)
sleepafternextclick = random.uniform(0.7, 1.2)
mouse.position = (xValue, yValue)
time.sleep(0.1)
mouse.click(Button.left, 2)
time.sleep(sleepafterdoubleclick)
pyautogui.press('right')
now I wrote a simple Dockerfile with the content:
FROM python:3.8
ADD myfile.py /
RUN pip install pynput
RUN pip install pyautogui
CMD [ "python", "./myfile.py" ]
After building the docker file I want to execute it and receive the error:
Traceback (most recent call last):
File “./NiklasMacLiker.py”, line 3, in
import pyautogui
File “/usr/local/lib/python3.8/site-packages/pyautogui/init.py”, line 241, in
import mouseinfo
File “/usr/local/lib/python3.8/site-packages/mouseinfo/init.py”, line 223, in
_display = Display(os.environ[‘DISPLAY’])
File “/usr/local/lib/python3.8/os.py”, line 675, in getitem
raise KeyError(key) from None
KeyError: ‘DISPLAY’
As I am new to Docker I have no clue, why it does not work properly. Any advice? Thanks in advance ![]()